I get a checkbox from OnItemClickListener using the snippet below
onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.w("TAG","onItemClick clicked position :"+position);
CheckBox cbx = (CheckBox)view.findViewById(R.id.c_checkbox);
if(cbx.isChecked()){
Toast.makeText(getApplicationContext(),
"Checked position " + shoppingList.get(position).getItem(),
Toast.LENGTH_SHORT).show();
}
I need to get all the items to check which list item is checked. For this, I used the fragment below
int firstPosition = list.getFirstVisiblePosition();
for(int i=firstPosition;i<=list.getCount();i++){
View v=list.getChildAt(i);
cbx = (CheckBox)v.findViewById(R.id.c_checkbox);
if(cbx.isChecked()){
}
}
in the cbx code below giving me a null exception.i pointer used the ViewHolder for the user adapter. Please give me a solution. Why does the same thing work in OnItemClickListener?
Regards, Rajendar
source
share