使用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);
}
};