I am using RecyclerView to display a list of items, and I need to update the state for one item by position. I update my item in the list and then call notifyItemChanged (int position) as follows:
myList.set(position, newModifiedItem); notifyItemChanged(position);
The item is updated successfully, but some other items are also randomly updated, and every time I look up and down the list of products, this update (a different icon state) is performed on other items.
I make changes to onBindViewHolder , where I check the position element by position and decide to set a different status.
Full adapter code:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private List<MyObj> myList; public MyAdapter(List<MyObj> list) { this.myList = list; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_item, parent, false); return new ViewHolder(view); } public void onBindViewHolder(final ViewHolder holder, final int position) { MyObj myObj = myList.get(position); boolean isSpecial = myObj.getMySpecialStatus(); holder.myItemTitle.setText(myObj.getTitle());
source share