【发布时间】:2019-05-18 06:10:09
【问题描述】:
我正在使用 Firebase-UI 和 firestore,现在有可能没有针对特定查询返回任何文档,那么我怎么知道呢?
progressBar.setVisibility(View.VISIBLE);
SharedPreferences prefs = getActivity().getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String city = prefs.getString("selectedCity", "pakistan");
Toast.makeText(getActivity(), city, Toast.LENGTH_SHORT).show();
Query query = db.collection("cities/"+city+"/"+category);
FirestoreRecyclerOptions<ExploreModel> options = new FirestoreRecyclerOptions.Builder<ExploreModel>()
.setQuery(query, ExploreModel.class)
.build();
adapter = new ExploreAdapter(options);
recyclerView.setAdapter(adapter);
progressBar.setVisibility(View.GONE);
adapter.setOnItemClickListener(new ExploreAdapter.OnItemClickListener() {
@Override
public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
// ExploreModel exploreModel = documentSnapshot.toObject(ExploreModel.class);
// String id = documentSnapshot.getId();
String path = documentSnapshot.getReference().getPath();
Toast.makeText(getActivity(), "Position" + position + " path :" + path, Toast.LENGTH_SHORT).show();
Intent detailActivityIntent = new Intent(getActivity(), SingleItemDetailsActivity.class);
detailActivityIntent.putExtra("document_path", path);
detailActivityIntent.putExtra("category",category);
startActivity(detailActivityIntent);
}
});
如果没有返回结果/文档,则会出现一个空屏幕,所以我想显示一个适当的空屏幕等。
【问题讨论】:
-
问题解决了吗?
-
没有,没有人回复兄弟
-
我猜你有我的问题。
-
您检查过 this 了吗?如果不起作用,请同时添加您的数据库结构和
ExploreModel类的内容。
标签: java android firebase google-cloud-firestore firebaseui