开发者

Android's ArrayAdapter - add strings listview instead of replace

This is how I add an 开发者_高级运维array to listview:

ListView my_listview = (ListView)findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, my_array);
my_listview.setAdapter(adapter);

my_array is uri of a file.

It works well. But next next time I want to array a new array, then I don't want to replace with with new one instead add new ones to the existing ones. How can I accomplish that?


You need to be using an ArrayList<String> my_array rather than a String[] my_array and then you can do:

my_array.addAll(other_array);

to add elements from a new array to your array. Then you can do:

adapter.notifyDataSetChanged();

to update your ListView with the new elements.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜