我想从Firebase Firestore数据库中获取数据。请告诉我在哪里修复代码。 或Firebase新版本,我无法使用
我想在HomeFragment上显示Post RecyclerView。
HomeFragment
public class HomeFragment extends Fragment {
private RecyclerView blog_list_view;
private List<BlogPost> blog_list;
private FirebaseFirestore mStore;
private FirebaseAuth mAuth;
private BlogRecyclerAdapter blogRecyclerAdapter;
private DocumentSnapshot lastVisible;
private Boolean isFirstPageFirstLoad = true;
public HomeFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home, container, false);
blog_list = new ArrayList<>();
blog_list_view = view.findViewById(R.id.blog_list_view);
blogRecyclerAdapter = new BlogRecyclerAdapter(blog_list);
blog_list_view.setLayoutManager(new LinearLayoutManager(container.getContext()));
blog_list_view.setAdapter(blogRecyclerAdapter);
mStore = FirebaseFirestore.getInstance();
mStore.collection("Posts").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot documentSnapshots, @Nullable FirebaseFirestoreException e) {
for(DocumentChange doc: documentSnapshots.getDocumentChanges()){
if(doc.getType() == DocumentChange.Type.ADDED){
BlogPost blogPost = doc.getDocument().toObject(BlogPost.class);
blog_list.add(blogPost);
blogRecyclerAdapter.notifyDataSetChanged();
}
}
}
});
return view;
}
}
错误的HomeFragment查找图片