检查是否没有针对Firebase ui查询类返回任何文档

时间:2019-05-18 06:10:10

标签: java android firebase google-cloud-firestore firebaseui

我正在将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);
            }
        });

如果没有返回结果/文档,则会出现空白屏幕,因此我想显示适当的空白屏幕。

1 个答案:

答案 0 :(得分:0)

您没有得到任何东西,因为模型类中字段的名称与数据库中字段的名称匹配。看到Line1: 2345 Line2: 2343 John Smith 01.01.1999 Line3: 2344 Dave Mustane 02.02.2000 Line4: 2345 Linda Fisher 03.03.1995 using System.IO; private void btn_speichern_Click(object sender, EventArgs e) { string dateipfad = @"C:\test"; string input; int ID = 0; using (StreamReader reader = new StreamReader(dateipfad)) input = reader.ReadLine() ?? ""; try { ID = Int32.Parse(input); ID = ++ID; } catch { MessageBox.Show("Error - cannot convert ID"); } using (StreamWriter newid = new StreamWriter(dateipfad)) { newid.WriteLine(ID); newid.Flush(); } //This is how I write the lines: using (StreamWriter writer = new StreamWriter(dateipfad, true)) { string row = string.Format("{0,-20}{1,-30}{2,-30}{3,-10}", ID, tbName.Text, tbVorname.Text, tbTag.Text + "." + tbMonat.Text + "." + tbJahr.Text); writer.WriteLine(row); MessageBox.Show("Erfolg!"); } this.Close(); } 吗?两者必须相同。

要解决此问题,您可以将模型类更改为如下形式:

mDescription

或者您可以使用注释:

description