开发者

ListView freaks out when I try to update the ArrayAdapter, is the header?

I have this ListView that is using an array adapter:

//global
ArrayList<Location> locations=new ArrayList<Location>(); //array list of location objects
ArrayAdapter<Location> theLocations;
ListView listView;

then in onCreateView of my Fragment:

    theLocations = new ArrayAdapter<Location>(mContext, 
          R.layout.location_row, locations);
    listView.setAdapter(theLocations);

This works pretty well I think, though if I try to update this adapter it freaks out...

//in my fragment, another dialog makes this call here to update the list.
public void onUIUpdate(Location l) { //listener call back when dialog "ok" clicked
    locations.add(l); //it is okay with this.
    theLocations.notifyDataSetChanged(); //dies
}

It dies with the error:

07-23 08:03:28.655: ERROR/AndroidRuntime(509): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView

does that mean it doesn't like the Location in the ArrayAdapter ??? does this mean I have to make my own custom listadapter? If I don't call theLocations.notifyDataSetChanged() everything is okay but then nothing updates... :(

I should note that th开发者_JAVA百科e toString() in the Location class is override to return a String name;

after a comment I tried this:

public void onUIUpdate(Location l) {
    locations.add(l);
    //theLocations.notifyDataSetChanged();
    WrapperListAdapter wr = (WrapperListAdapter)listView.getAdapter();
    ArrayAdapter aa=(ArrayAdapter)wr.getWrappedAdapter();
    aa.notifyDataSetChanged();
}

LOL no luck here, was a stab in the dark. Also wandering if its the addHeaderView I used on the ListView? I am not sure if it makes it immutable in the future using addHeaderView?


I won't comment about ListView design, it is very ugly, but I do listView.getAdapter().getWrappedAdapter().notifyDataSetChabged(); and it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜