Now I am using RecyclerView with CheckBox. My Goal is get selected Checkbox list. Here My Problem is while I try to select any one Checkbox means it select two Checkbox at the same time. For example I am select in 0th position Checkbox but It automatically select 0th and 13th Both position Checkbox are getting selected.
Here I have to attached my RecyclerView Adapter Class. Please any one help me..
Thanks in Advance.
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
private ArrayList<ModuleViewModel> items = new ArrayList<>();
private OnItemCheckListener onItemClick;
private Context mContext;
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_modules_list, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
final ModuleViewModel currentItem = items.get(position);
holder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.checkbox.setChecked(
! holder.checkbox.isChecked());
if ( holder.checkbox.isChecked()) {
onItemClick.onItemChecked(currentItem);
} else {
onItemClick.onItemUnchecked(currentItem);
}
}
});
}
@Override
public int getItemCount() {
return items.size();
}
public interface OnItemCheckListener {
void onItemChecked(ModuleViewModel item);
void onItemUnchecked(ModuleViewModel item);
}
public MyAdapter (Context context,ArrayList<ModuleViewModel> items, @NonNull OnItemCheckListener onItemCheckListener) {
this.mContext = context;
this.items = items;
this.onItemClick = onItemCheckListener;
}
static class MyViewHolder extends RecyclerView.ViewHolder {
CheckBox checkbox;
View itemView;
public MyViewHolder(View itemView) {
super(itemView);
this.itemView = itemView;
checkbox = (CheckBox) itemView.findViewById(R.id.uiCkbModule);
checkbox.setClickable(false);
}
public void setOnClickListener(View.OnClickListener onClickListener) {
itemView.setOnClickListener(onClickListener);
}
}
}
This is My Adapter calling Code
mModuleListAdapter = new ModuleListAdapter(mContext, mModuleListModel, this);
mRvModuleView.setAdapter(mModuleListAdapter);
Aucun commentaire:
Enregistrer un commentaire