I have a ListActivity with an array adapter declared like arrayAdapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_checked);
This shows a bunch of rows with checkmarks on the far right. Can you tell me how to get a reference to those checkmarks or how to check/uncheck them?
views:
361answers:
2
A:
The closest I can do is change the checkmark after a cell is clicked using:
@Override
protected void onListItemClick( ListView l, View v, int position, long id)
{
CheckedTextView textView = (CheckedTextView)l.getChildAt(position);
text.setChecked(!textView.isChecked());
super.onListItemClick (l, v, position, id);
}
I would still like to be able to set the checkmarks without the user touching any cells.
bmalicoat
2010-02-05 05:05:07
A:
The CheckedTextView itself handles the checkbox. It is passed in as the second argument (View v) in the onListItemClick handler. So, you can simplify your code as follows:
@Override
protected void onListItemClick( ListView l, View v, int position, long id)
{
CheckedTextView textView = (CheckedTextView)v;
textView.setChecked(!textView.isChecked());
}
Brian Cooley
2010-05-19 23:11:37