Reputation: 995
I am working with a search activity which extends ListActivity. I initialize my adapter as follows,
adapter = new ArrayAdapter<String>(SearchActivity.this, android.R.layout.simple_list_item_multiple_choice, testArrayList);
l.setAdapter(adapter);
However, I am not sure how to get the checkboxes to work. I have an onListItemClick method which works fine for clicking an actual list item.
public void onListItemClick(ListView l, View v, int position, long id) {
Log.d("Test", testArrayList.get(position));
MainActivity test = new MainActivity();
test.addToArray(testArrayList.get(position));
}
Upvotes: 0
Views: 948
Reputation: 7306
You need to create custom adapter to handle event on check box in list
Upvotes: 1
Reputation: 2185
First Create custom adapter & In getView() method of custom adapter use below code:
itemName = (TextView) convertView.findViewById(R.id.label);
checkbox = (CheckBox) convertView.findViewById(R.id.check);
((CheckBox) (checkbox)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
CheckBox c = (CheckBox) view;
// your code
}
});
Upvotes: 0