For the record, since it's always good to post solutions (albeit three
months later)...
The only way I ever got this to work in the end was to use my own custom
row layout and inflate that in getView(), rather than using
android.R.layout.simple_list_item_multiple_choice. Everything worked just
the way I'd expected it to all along when I did that, including the
ListView updating instantly and correctly whenever I changed the data via
the ArrayAdapter, and notifyDatasetChanged() doing likewise when I was
changing the data directly.
--Calum.
On Friday, November 25, 2011 12:41:43 AM UTC, scottishwildcat wrote:
>
> Hi Jon... thanks for the reply. Thought you might have been onto something
> there, as I wasn't storing the ArrayList that was passed into the
> ShoppingListAdapter constructor at all -- I was just directly accessing the
> one defined in the parent activity, as you noticed. So now my adapter
> constructor looks like:
>
> public class ShoppingListAdapter extends ArrayAdapter<ShoppingListItem>{
>
>
> private ArrayList<ShoppingListItem> itemList;
>
>
> public ShoppingListAdapter(Context c, int layoutId,
> ArrayList<ShoppingListItem> itemList){
>
> super(c, layoutId, itemList);
>
> this.itemList = itemList;
>
> }
>
>
> Unfortunately, having rectified that, and tried replacing the lines you
> suggested with both:
>
> rowView.setText(itemList.get(position).getName());
> rowView.setChecked(itemList.get(position).isChecked());
>
>
> and
>
>
> rowView.setText(getItem(position).getName());
>
> rowView.setText(getItem(position).isChecked());
>
>
> the behavior appears to be exactly the same as my original version in both
> cases. (Your suggestion doesn't work verbatim, as getItem is not defined on
> itemList).
>
> I guessed the checkbox issue might be something to do with view recycling
> too, but I've tried both working with the recycled convertView when
> available, and just inflating a new view every time regardless, and that
> doesn't seem to make any difference either...
>
> Cheers,
> Calum.
>
--
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