I am having CheckBox inside of RecyclerView. I am setting item by storing values into Object class List<CartRes>
where the data have been gotten from DataBase and I populated these into RecyclerView. But when I click CheckBox app is closed due to NullPointer Exception.
MyCode:
ChatListAdapter.java:
holder.chkSelected.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
CartRes cartRes = (CartRes) cb.getTag(); // Getting NPE at here.
cartRes.setSelected(cb.isChecked());
RestaurantFilter.get(pos).setSelected(cb.isChecked());
Toast.makeText(
v.getContext(),
"Clicked on Checkbox: " + cb.getText() + " is "
+ cb.isChecked(), Toast.LENGTH_LONG).show();
}
});
Aucun commentaire:
Enregistrer un commentaire