I'm creating a view where it will list about 30 items, each with its
own checkbox. I'm using the
android.R.layout.simple_list_item_multiple_choice layout for this.
I have it displaying on the screen with my items and the checkboxes
and it looks great. But here's the problem. When I click on one, it
checkmarks, but when I scroll to the next page of items it shows the
item in the exact same position is also checked.
Example of what I mean:
The emulator shows me 7 results on the screen at a time. If I click
the checkbox for the first item, it enables. Then I scroll the screen
down past the 7th item I see that the 8th item is checked, even though
it shouldn't be. If I scroll down again to I see another item
checked. The only one that should be checked is the one I actually
clicked on. I can repeat this same exact problem for for any position
in the item list. I must be doing something wrong in the code.
Here's my code -- not much to it:
Creating the adapter:
ArrayAdapter<String> categoryList = new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
android.R.id.text1,
UserData.CATEGORY_NAMES);
setListAdapter(categoryList);
Then the event:
@Override
public void onListItemClick(ListView l, View v, int position, long
id) {
//CheckedTextView textView = (CheckedTextView)l.getChildAt
(position);
//textView.setChecked(!textView.isChecked());
CheckedTextView textView = (CheckedTextView)v;
textView.setChecked(!textView.isChecked());
}
I tried both ways in the above method. Both had the same result.
Anyone know what the problem might be?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en