You can add onItemClickListener to your listview , on item click check the state of you checkbox and do action you want.
ListView lv = (ListView) findViewById(R.id.listview);
ArrayList<String> stateList =Handler.getList();
String[] catalogList = new String[stateList.size()];
catalogList=stateList.toArray(catalogList);
lv.setAdapter(new ArrayAdapter<String>(Catalog.this,
android.R.layout.simple_list_item_multiple_choice, catalogList));
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
CheckedTextView checkedTextView =
(CheckedTextView) view.findViewById(android.R.id.text1);
System.out.println(
checkedTextView.getText()+":"+
!checkedTextView.isChecked() //because the onItemClick fired before checkedTextView change its state
);
}
});
for why see this
you also can do it by implement custom adapter. a dirty example following:
public class CheckListAdapter extends BaseAdapter {
//omitted
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int pos = position; // if you need positon in this item's action
View item = mInflater.inflate(R.layout.list_item_checkboxt, null);
(CheckBox)item.findViewById(R.id.checkbox)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// do your action here
}
});
}
}
more effective of use adapter take a look this post!