确保Firebase数据库中有数据,可以通过Firebase Console查看。
检查Recyclerview Adapter的构造函数是否已正确初始化FirebaseRecyclerOptions对象,是否将正确的类型传递给FirebaseRecyclerOptions.Builder:
FirebaseRecyclerOptions options =
new FirebaseRecyclerOptions.Builder()
.setQuery(query, MyModel.class)
.build();
MyAdapter adapter = new MyAdapter(options);
RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("myData");
Query query = ref.orderByChild("title");
FirebaseRecyclerOptions options =
new FirebaseRecyclerOptions.Builder()
.setQuery(query, MyModel.class)
.build();
MyAdapter adapter = new MyAdapter(options);
如果是Firestore,请确保您的查询已正确设置:
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference myRef = db.collection("myData");
Query query = myRef.orderBy("title", Query.Direction.ASCENDING);
FirebaseRecyclerOptions options =
new FirebaseRecyclerOptions.Builder()
.setQuery(query, MyModel.class)
.build();
MyAdapter adapter = new MyAdapter(options);
如果这些解决方法都无效,请检查您的Firebase数据库规则是否正确设置,以确保您的应用程序具有适当的读取和写入权限。