Reputation: 679
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final XContacts mContact = visibleObjects.get(position);
holder.Name.setText(mContact.getName());
holder.InviteTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.InviteTextView.setText("INVITED");
}
});
}
holder.Name.setText
:- Here i am names to recyclerview
holder.InviteTextView.setOnClickListener
:- When I click on one item[invite]
. After I scroll down multiple items are get invited without that item being clicked on.
My problem is:
Abninav kashayp invited if I scroll down I get problems
Upvotes: 0
Views: 484
Reputation: 6988
RecyclerView, as the name says, is recycling views, that's why you are seeing 'INVITED' in other views.
In order to fix the issue, in onClickListener you should set a flag in your XContacts object:
mContact.setInvited(true);
Then you should change your onBindViewHolder code to also set the InviteTextView, just after setting the Name:
if (mContact.isInvited()) {
holder.InviteTextView.setText("INVITED");
}
else {
holder.InviteTextView.setText("INVITE");
}
Upvotes: 1