私はFirebaseRecyclerAdapter
を使用して、Firebaseにデータが追加されるとビューを動的に取り込みます。RecyclerViewを再投入せずにViewHolderを更新
ただし、データが変更されるとRecyclerView
が表示されるビューをFirebase
に変更する必要があります。たとえば、私は人口統計の各ビューにカウンターを持っています。人々がそのトピックに投票すると、カウンターを増やしたいと思っています:RecyclerView
に設定されている各ビューにタグを設定し、画面に表示されている現在のビューを取得し、そのビューを動的に更新する方法を見つけることができます。私は一種の私が進むだろうか失ったが、ここで私のPollHolderでいます:ここで
public static class PollHolder extends RecyclerView.ViewHolder {
TextView mPollQuestion;
TextView mVoteCount;
ImageView mPollImage;
View mView;
String mTag;
public PollHolder(View itemView) {
super(itemView);
mPollQuestion = (TextView) itemView.findViewById(R.id.latest_item_question);
mPollImage = (ImageView) itemView.findViewById(R.id.pollThumbNailImage);
mVoteCount = (TextView) itemView.findViewById(R.id.latest_item_poll_count);
this.mView = itemView;
}
public void setVoteCount (String voteCount){
mVoteCount.setText(voteCount);
}
public void setTag(String tag){
this.mTag = tag;
}
public View getViewByTag(String tag){
return mView;
}
}
はRecyclerView
での図です。私は右下隅のカウンタを更新したいが、もう一度、完全に再作成/再投入したくない。RecyclerView
。