在我的活动中,我使用RecyclerView
使用FirebaseRecyclerAdapter
绘制列表:
mChatDetailsAdapter = new ChatDetailsAdapter(
this,
MessageData.class,
R.layout.layout_chat_item,
ChatDetailsAdapter.MessageViewHolder.class,
query);
mChatListView.setHasFixedSize(true);
LinearLayoutManager lLinearLayoutManager = new LinearLayoutManager(ChatDetailsActivity.this, LinearLayoutManager.VERTICAL, false);
lLinearLayoutManager.setStackFromEnd(true);
lLinearLayoutManager.setReverseLayout(true);
mChatListView.setLayoutManager(lLinearLayoutManager);
mChatListView.addItemDecoration(new VerticalSpaceItemDecoration(UIUtils.dpToPx(ChatDetailsActivity.this, 8)));
mChatListView.setAdapter(mChatDetailsAdapter);
适配器负责视图:
@Override
protected void populateViewHolder(final MessageViewHolder pViewHolder, final MessageData pMessageData, int pPosition) {
pViewHolder.mMessageTextView.setText(pMessageData.getMessage());
pViewHolder.mSelfLinearLayout.setVisibility(View.VISIBLE);
pViewHolder.mTimeTExtView.setText(StringUtils.toMessageTimeString(mContext, pMessageData.getTime()));
}
在onBindViewHolder()
方法中,我基本上做同样的事情,从模型中分配数据(在查看日志消息后正常工作)。现在,当滚动列表时,RecyclerView
会更改其值并且无法正确回收,我不知道为什么。任何的想法?