Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓&x27;s ArrayAdapter-添加字符串列表视图而不是替换_Android_Android Listview_Android Adapter - Fatal编程技术网

Android 安卓&x27;s ArrayAdapter-添加字符串列表视图而不是替换

Android 安卓&x27;s ArrayAdapter-添加字符串列表视图而不是替换,android,android-listview,android-adapter,Android,Android Listview,Android Adapter,以下是如何将数组添加到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); ListView m

以下是如何将数组添加到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);
ListView my_ListView=(ListView)findViewById(R.id.listView1);
ArrayAdapter=新的ArrayAdapter(这个,android.R.layout.simple\u list\u item\u 1,my\u数组);
my_listview.setAdapter(适配器);
my_数组是文件的uri


它工作得很好。但是下一次我想数组一个新的数组时,我不想用新的数组替换,而是在现有的数组中添加新的数组。如何实现这一点?

您需要使用
数组列表my_array
而不是
字符串[]my_array
,然后您可以执行以下操作:

my_array.addAll(other_array);
adapter.notifyDataSetChanged();
将新数组中的元素添加到数组中。然后你可以做:

my_array.addAll(other_array);
adapter.notifyDataSetChanged();
使用新元素更新ListView