Are their known issues with ArrayAdapters not updating their corresponding
ListViews, even when you're just using the standard add(), remove(),
insert() methods that are supposed to update them automatically?
In my activity I'm declaring:
public class ShoppingListAdapter extends ArrayAdapter<ShoppingListItem>{
>
> public ShoppingListAdapter(Context c, int layoutId,
> ArrayList<ShoppingListItem> itemList){
>
> super(c, layoutId, itemList);
>
> }
>
> @Override
>
> public View getView(int position, View convertView, ViewGroup parent) {
>
>
> CheckedTextView rowView = (CheckedTextView)convertView;
>
>
>
> if (rowView==null){
>
> LayoutInflater inflater = getLayoutInflater();
>
> rowView = (CheckedTextView)inflater.inflate(android.R.layout.
> simple_list_item_multiple_choice, parent, false);
>
> }
>
> rowView.setText(shoppingItems.getItem(position).getName());
>
> rowView.setChecked(shoppingItems.getItem(position).isChecked());
>
>
> return rowView;
>
> }
>
> }
>
> private ShoppingListAdapter slAdapter;
>
where ShoppingListItem is a simple class containing a String (the shopping
list item name) and a Boolean (whether it is currently checked in the
ListView).
In some parts of my activity, adding or removing list items using the
adapter's add() and remove() methods works fine. In others, the view
doesn't update itself, even I explicitly call notifyDataSetChanged, which I
shouldn't have to (notification is turned on by default for new
ArrayAdapters). In one case, re-assigning the existing adapter to the
ListView immediately after calling remove() inexplicably triggers the
correct behavior. In other cases, it has no effect. If I remove() the first
item in the array, it will disappear from the ListView, but its checkbox
state will transfer to the new first item in the ListView. If I remove()
the last item and then add a new one, I won't see the new item, but instead
whatever used to be the last item before I deleted it.
Are ArrayAdapters just fundamentally somewhat broken? (I'm currently
targeting 2.3.3, API 10, FWIW.)
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