我在我的应用中广泛使用了Firebase RecyclerViewAdapter,但由于下面的代码没有触发populateViewHolder而没有首先加载任何数据,我无法显示加载完成消息初始负荷
RecyclerView recycler = (RecyclerView) findViewById(R.id.messages_recycler);
recycler.setHasFixedSize(true);
recycler.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(Chat.class, android.R.layout.two_line_list_item, ChatHolder.class, mRef) {
@Override
public void populateViewHolder(ChatHolder chatMessageViewHolder, Chat chatMessage, int position) {
chatMessageViewHolder.setName(chatMessage.getName());
chatMessageViewHolder.setText(chatMessage.getText());
}
};
recycler.setAdapter(mAdapter);
答案 0 :(得分:2)
此功能涵盖了您所描述的内容:Handle empty state for recycleview。您可以通过在适配器中实现onDataChanged()
来解决此问题。一个snippet from the sample app of FirebaseUI:
@Override
protected void onDataChanged() {
// if there are no chat messages, show a view that invites the user to add a message
mEmptyListView.setVisibility(
mRecyclerViewAdapter.getItemCount() == 0 ? View.VISIBLE : View.INVISIBLE
);
}
答案 1 :(得分:0)
if(chatMessage.getName()。equals(&#34;&#34;)){// null value} else { //执行代码}
答案 2 :(得分:0)
覆盖onDataChanged()并检入
jar