I have a listview with a checkboxes in each row. I am using the viewholder pattern to load the list, like this:
View view = convertView;
if(view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.setting_list_item, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.cbCat = (CheckBox) view.findViewById(R.id.cbCat);
view.setTag(viewHolder);
}
ViewHolder vh = (ViewHolder) view.getTag();
vh.cbCat.setText(bt.getName());
But when I try to get the checked checkboxes, like this :
for(int i = lvCatList.getFirstVisiblePosition(); i < settingAdapter.getCount(); i++) {
View v = lvCatList.getChildAt(i);
CheckBox cbx = (CheckBox) v.findViewById(R.id.cbCat);
if(cbx != null && cbx.isChecked()) {
toast += " / " + settingAdapter.getItem(i).getName();
Log.d("CHECKED", toast);
}
Only the visible checkboxes can be get. And if the checkbox is not visible in the screen it throws exceptions.
How to check whether the chekboxes in the list are checked or not.?
}
You can add selected checkbox value to arraylist when checking on checkbox
When you need to check whether the checkbox is checked just refer SelectedBox