因此,我正在开发一个向用户显示他正在从事的项目列表的应用程序。我正在使用firebase firestore和firestorerecycleradapter在recyclerview中显示列表。 在将应用程序置于后台并再次打开之前,不会填充recyclerview。一旦在选项卡布局中更改了片段,recyclerview就会再次消失。 我的系统的工作方式是将用户的访问ID与项目的访问ID匹配并显示它们。
大多数有相同问题的人都尝试从代码中删除行hasfixedsize(true)。但这对我不起作用。
这是OnCreateView方法
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_projects, container, false);
user = mAuth.getCurrentUser();
recyclerView = view.findViewById(R.id.projectsrv);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
FirebaseApp.initializeApp(getContext());
if (isDesignerCodeChanged() && user != null) {
Query query = db.collection("projects")
.whereEqualTo("AccessID", AccessID);
FirestoreRecyclerOptions<Projectsdata> options = new FirestoreRecyclerOptions.Builder<Projectsdata>()
.setQuery(query, Projectsdata.class)
.build();
firestoreRecyclerAdapter = new FirestoreRecyclerAdapter(options);
firestoreRecyclerAdapter.notifyDataSetChanged();
recyclerView.setAdapter(firestoreRecyclerAdapter);
return view;
}
// recyclerView.setAdapter(firestoreRecyclerAdapter);
// firestoreRecyclerAdapter.setOnItemClickListener(this);
return view;
}
OnStart方法
@Override
public void onStart() {
super.onStart();
if (isDesignerCodeChanged() && user != null) {
Query query = db.collection("projects")
.whereEqualTo("AccessID", AccessID);
FirestoreRecyclerOptions<Projectsdata> options = new FirestoreRecyclerOptions.Builder<Projectsdata>()
.setQuery(query, Projectsdata.class)
.build();
firestoreRecyclerAdapter = new FirestoreRecyclerAdapter(options);
recyclerView.setAdapter(firestoreRecyclerAdapter);
}
firestoreRecyclerAdapter.startListening();
}
OnStop方法
@Override
public void onStop() {
super.onStop();
Query query = db.collection("projects")
.whereEqualTo("AccessID", AccessID);
FirestoreRecyclerOptions<Projectsdata> options = new FirestoreRecyclerOptions.Builder<Projectsdata>()
.setQuery(query, Projectsdata.class)
.build();
firestoreRecyclerAdapter = new FirestoreRecyclerAdapter(options);
recyclerView.setAdapter(firestoreRecyclerAdapter);
firestoreRecyclerAdapter.stopListening();
}
OnCreate方法
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
db = FirebaseFirestore.getInstance();
}
我检查了logcat并发现以下行: 2019-05-22 22:40:44.007 7073-7073 / com.example.hellovorld E / RecyclerView:未连接适配器;跳过布局