来自Firebasedatabase的数据未显示在我的recyclerView中,我使用FireBaseRecyclerAdapter

时间:2019-07-17 06:29:37

标签: android firebase android-recyclerview

使用FirebaseRecyclerAdapter在我的RecyclerView中不会显示数据库中的数据

options =  new FirebaseRecyclerOptions.Builder<ChatMessage>().setQuery(ref.child("chat"), ChatMessage.class).build();

    adapter = new FirebaseRecyclerAdapter<ChatMessage, chat_rec>(options) {

        @Override
        protected void onBindViewHolder(@NonNull chat_rec viewHolder, int position, @NonNull ChatMessage model) {

         if (model.getMsgUser().equals("user")) {

                viewHolder.rightText.setText(model.getMsgText());

                viewHolder.rightText.setVisibility(View.VISIBLE);
              viewHolder.leftText.setVisibility(View.GONE);
        }
        else {
                viewHolder.leftText.setText(model.getMsgText());

                viewHolder.rightText.setVisibility(View.GONE);
                viewHolder.leftText.setVisibility(View.VISIBLE);
        }

        }
        @NonNull
        @Override
        public chat_rec onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View view = LayoutInflater.from(Chatbot.this).inflate(R.layout.msglist, parent, false);
            return new chat_rec(view);
        }

    };

0 个答案:

没有答案