开发者

Changing listview adapter back and forth?

When the user first loads the listview, it pulls the date column from an sqlitedb and populates the list. When they click on a date, I put that date in a variable. I then want to display a list of items from an array. And then when they click one of those items, it again pulls data from an sqlitedb and populates.

So initial listview:

12-2010

01-2011

03-2011

04-2011

click on any date, set mDate = clicked item

change listview to display what's in an array, then it's looking look

Option 1

Option 2

Option 3

Option 4

click开发者_Python百科 on an option, set mOption = clicked item

change listview to pull data based on mOption from the db.

I know how to get the listview to pull info from each of these sources, what I'm not clear on, is the best way to handle these adapter switches. Any suggestions?


There are two options. You can have multiple ListView that each have their own adapter that you switch between or you can have multiple adapters that you just set to the ListView. Personally I would go with option 1 so you can put the ListViews in a ViewSwitcher and animate the transitions.


If data may change at any moment, the cheapest and most reusable way I believe would be to use:

public void updateContents (ListView lv, List<String> list) {
    ArrayAdapter<String> myAdapter = lv.getAdapter();
    myAdapter.clear();
    myAdapter.AddAll (list);
    lv.setAdapter(myAdapter);
}

But, this only works in android 4.0 or later. 2.3 and lower does NOT support ArrayAdapter.AddAll(object);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜