поэтому я сделал RecyclerView и заполнил его данными из Firestore, все это работает нормально, но когда я пытаюсь отфильтровать определенные поля, я не получаю данных. Я использую FirebaseUI. Так, например, когда я фильтрую по имени поля, оно работает совершенно нормально, например:
CollectionReference ref = db.collection("exercises");
Query query = ref.whereEqualTo("name", "SQUAT");
, но с другой стороны, если это сделать, оно не будет работать:
CollectionReference ref = db.collection("exercises");
Query query = ref.whereEqualTo("type", "barbell");
Здесь мой полный код:
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;
public class ExerciseFragment extends Fragment {
private static final String TAG = "TAG";
private RecyclerView mView;
FirebaseFirestore db;
private FirestoreRecyclerAdapter adapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_exercise, container, false);
db = FirebaseFirestore.getInstance();
mView = view.findViewById(R.id.recycler_view);
//Query
CollectionReference ref = db.collection("exercises");
Query query = ref.whereEqualTo("name", "SQUAT");
//RecyclerOptions
FirestoreRecyclerOptions<Exercises> options = new FirestoreRecyclerOptions.Builder<Exercises>()
.setQuery(query, Exercises.class)
.build();
//Adapter
adapter = new FirestoreRecyclerAdapter<Exercises, ExerciseViewHolder>(options) {
@NonNull
@Override
public ExerciseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_list_layout, parent, false);
return new ExerciseViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull ExerciseViewHolder holder, int position, @NonNull Exercises model) {
String uri = model.getImageurl();
Glide.with(holder.itemView.getContext()).load(uri).into(holder.imageView);
holder.list_name.setText(model.getName());
holder.list_desc.setText(model.getDesc());
}
};
mView.setHasFixedSize(true);
mView.setLayoutManager(new LinearLayoutManager(getContext()));
mView.setAdapter(adapter);
return view;
}
private class ExerciseViewHolder extends RecyclerView.ViewHolder {
private ImageView imageView;
private TextView list_name;
private TextView list_desc;
public ExerciseViewHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.listImage);
list_name = itemView.findViewById(R.id.listTittle);
list_desc = itemView.findViewById(R.id.listSubtitle);
}
}
@Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
@Override
public void onStart() {
super.onStart();
adapter.startListening();
}
}
это моя структура БД