문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top