Similar question have been asked, but i can\'t get any of them work.
What i want is to select item in RecyclerView, change the background of that item view, and stor
Make global variable to store position and handle click listener in ViewHolder. Onclick of item, change the global position value like
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
globalPosition=getAdapterPosition();
notifyDataSetChanged();
}
});
then in onBindViewHolder
if(postion==globalPosition)
{
//change color like
textview.setTextColor(Color.RED);
}
else
{
//revert back to regular color
textview.setTextColor(Color.WHITE);
}
with this code, the item you clicked get red colored and all other wiil be in white.