Я решил перейти с Firestore на phpMyAdmin, столкнулся с проблемой, раньше чтобы получить определённую строку из БД Firestore я писал следующее
FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
DocumentReference documentReference2 = firebaseFirestore.collection("InformationEN").document(itemTasksAdapter.get(position).getid());
documentReference2.get().addOnCompleteListener(task ->
{
if (task.isSuccessful()) {
DocumentSnapshot documentSnapshot = task.getResult();
Bundle bundle = new Bundle();
bundle.putString("id", documentSnapshot.getString("id"));
MainActivity.curFragment.setArguments(bundle);
}
});
Таким образом я получал в Bundle
нужную строку из БД Firestore, но как сделать тоже самое из БД phpMyAdmin мне не понятно, я написал следующий код
ApiInterfaceInformationEN apiInterface = ApiClient.getApiClient().create(ApiInterfaceInformationEN.class);
Call<ArrayList<ItemInformation>> call = apiInterface.getContact("InformationEN", itemTasksAdapter.get(position).getid());
call.enqueue(new Callback<ArrayList<ItemInformation>>() {
@Override
public void onResponse(@NonNull Call<ArrayList<ItemInformation>> call, @NonNull Response<ArrayList<ItemInformation>> response) {
}
@Override
public void onFailure(@NonNull Call<ArrayList<ItemInformation>> call, @NonNull Throwable t) {
MainActivity.Toast("Error\n" + t.toString());
}
});
Из ApiClient
я получаю ссылку, а с помощью ApiInterfaceInformationEN
я указываю нужное слово для определения позиции с нужными данными в БД, осталось как-то получить непосредственно данные, как это сделать?
ApiInterfaceInformationEN
public interface ApiInterfaceInformationEN {
@GET("getDataInformationEN.php")
Call<ArrayList<ItemInformation>> getContact(
@Query("item_type") String item_type,
@Query("key") String keyword
);
}
ApiClient
public static final String BASE_URL = "http://ссылка/";
public static Retrofit retrofit;
public static Retrofit getApiClient(){
if (retrofit==null){
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
response.body()
с типомArrayList<ItemInformation>
делайте с ними все что хотите: итерируйте, передавайте в activity... хотя бы начните с лога того, что вам приходит...