I'm trying to add a checkbox (i'm doing it with imageview) to my filterable recyclerview. Checking works fine: Checking without using searchview
but when i search for something, only first item of my list is checked: After searching and deleting text in searchview
I'll post my code below:
Shop Selected Interface
public interface NearestShopActivityAdapterListener {
void onShopSelected(FShop shop, View view);
}
My View Holder
public class MyHolder extends RecyclerView.ViewHolder{
public TextView name, address;
public ImageView logo;
public MyHolder(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.activityNearestShopListItemUhop);
address = (TextView) itemView.findViewById(R.id.activityNearestShopListItemAddress);
logo = (ImageView) itemView.findViewById(R.id.activityNearestShopListItemImage);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onShopSelected(filteredShopList.get(getAdapterPosition()),view);
}
});
}
onShopSelected function
@Override
public void onShopSelected(FShop shop, View view) {
if(checkList.contains(shop.getShopId())){
mImgViewCheckBox = (ImageView) view.findViewById(R.id.checkBoxNearestShop);
mImgViewCheckBox.setImageResource(R.drawable.checkbox_selector_not_checked);
checkList.remove(shop.getShopId());
}else {
mImgViewCheckBox = (ImageView) view.findViewById(R.id.checkBoxNearestShop);
mImgViewCheckBox.setImageResource(R.drawable.ic_checked);
checkList.add(shop.getShopId());
}
}
Where I am wrong? I would try to associate the ImageView mImgViewCheckBox with the Shop id and not with its position in the recyclerview, but I have no idea on how to do it. Thnak you in advance.
Aucun commentaire:
Enregistrer un commentaire