使用FirebaseRecyclerAdapter的RecyclerView在滚动时显示错误的值

时间:2017-04-29 10:33:13

标签: android firebase firebase-realtime-database android-recyclerview firebaseui

在我的活动中,我使用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会更改其值并且无法正确回收,我不知道为什么。任何的想法?

0 个答案:

没有答案