如果查询或路径中有数据,则它会在FirestoreRecyclerAdapter中显示数据。但是当那条路上没有数据的时候

时间:2018-02-15 13:26:31

标签: android android-recyclerview google-cloud-firestore recycler-adapter firebaseui

我使用FirestoreRecyclerAdapter查询。我显示加载,直到它没有进入onBindViewHolder()。如果涉及onBindViewHolder,则关闭对话框。

但是在我的场景中,没有数据进入查询,它没有进入onBindViewHolder所以我无论如何都没有找到关闭它。这是我的代码。请帮忙。

Query query = GlobalApplication.applianceRef.whereEqualTo("applianceType", appType);

FirestoreRecyclerOptions < RoomAppliance > response = new FirestoreRecyclerOptions.Builder < RoomAppliance > ()
    .setQuery(query, RoomAppliance.class)
    .build();

if (dialog != null) {
    dialog.show();
}

adapter = new FirestoreRecyclerAdapter < RoomAppliance, ApplianceActivity.ViewHolder > (response) {
    @Override
    public void onBindViewHolder(final ApplianceActivity.ViewHolder holder, final int position, final RoomAppliance model) {
        dialog.dismiss();
    }

    @Override
    public ApplianceActivity.ViewHolder onCreateViewHolder(ViewGroup group, int i) {
        View view = null;
        try {
            view = LayoutInflater.from(group.getContext())
                .inflate(R.layout.user_appliance, group, false);
        } catch (Exception e) {
            Log.e("error", e.getMessage());
        }
        return new ApplianceActivity.ViewHolder(view);
    }
};

1 个答案:

答案 0 :(得分:1)

我得到了答案

  @Override
                    public void onDataChanged() {
                        if(dialog != null && dialog.isShowing()){
                            dialog.dismiss();

                        }

                        if(getItemCount() == 0){

                            remoteListRV.setVisibility(View.GONE);
                            msgTv.setVisibility(View.VISIBLE);
                            msgTv.setText("No "+ appType +" Available  !!!!");


                        }else {

                            remoteListRV.setVisibility(View.VISIBLE);
                            msgTv.setVisibility(View.GONE);

                        }

                    }