Reputation: 486
I'm using a simple_list_item_checked
listview and am programmatically setting checked to true / false. However, when a user selects an item from the list, it changes the state of the checkbox.
It only shows it for a second, because it immediately redirects to another activity.
How can I prevent the checkbox from changing when the user clicks on it?
Upvotes: 2
Views: 2504
Reputation: 486
I ended up creating a custom ArrayAdapter class, following this tutorial http://www.mkyong.com/android/android-listview-example/
But instead of using if String.equals(" "), I used a boolean value called checked. If it's true, use a "checked box" image and if false, use an "unchecked box" image.
Thanks for the help guys. I hope this is help to people in the future.
Upvotes: 0
Reputation: 4340
change your CheckBox clickable property to false programatically as follows
theCheckBox.setClickable(false);
Upvotes: 5
Reputation: 3814
Maybe you only need to overwrite the onListItemClick()
method of the ListActivity
, if you use this class as base class for your Activity
.
Then you can use the setItemChecked()
method of the ListView
passed as argument to control the state of the checkbox. I'm using in a project a simple_list_item_single_choice
listview and it works quite well.
Upvotes: 2
Reputation: 6201
Create a custom AdapterView
instance of simple_list_item_checked. That will solve your problem.
Upvotes: 0