I have a recyclerview in which I have some items, when I click on any of them, an imageview appears on the selected item, this part I already manage to do but my problem is that when I scroll down and go back up element that became visible is duplicated in other items that I have not selected. How could I solve this situation? Thank you in advance.
When I select the item.
is duplicated in another item.
Adapter code:
public class EmployeeRecyclerViewAdapter extends
RecyclerView.Adapter<EmployeeRecyclerViewAdapter
.ViewHolder> {
private List<Employee> mEmployees = new ArrayList<>();
private ClickItem clickItemAc;
private View viewGeneral;
public EmployeeRecyclerViewAdapter(List<Employee> employeeList,ClickItem clickItem) {
this.mEmployees.addAll(employeeList);
this.clickItemAc = clickItem;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
final View view = inflater.inflate(R.layout.list_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final Employee employee = mEmployees.get(position);
holder.name.setText(employee.getName());
holder.role.setText(employee.getRole());
}
public void updateEmployeeListItems(List<Employee> employees) {
final EmployeeDiffCallback diffCallback = new EmployeeDiffCallback(this.mEmployees, employees);
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffCallback);
this.mEmployees.clear();
this.mEmployees.addAll(employees);
diffResult.dispatchUpdatesTo(this);
}
@Override
public int getItemCount() {
return mEmployees.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements ClickItem {
private final TextView role;
private final TextView name;
private final ImageView status;
public ViewHolder(View itemView) {
super(itemView);
viewGeneral = itemView;
name = (TextView) itemView.findViewById(R.id.employee_name);
role = (TextView) itemView.findViewById(R.id.employee_role);
status = (ImageView) itemView.findViewById(R.id.status);
name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickItemAc.clickItem(viewGeneral);
}
});
}
@Override
public void clickItem(View v) {
}
}
}