The Arrayadapter class can act as an adapter resource for the ListView, and can dynamically add new data to the adapter, which is what the Arrayadapter.add () method does. However, if an error occurs when using this method, it is necessary to check the parameters in the Arrayadapter construction method t[] objects, if this parameter is set to a fixed-size data type, it cannot be added. The Add () method actually adds data to this parameter dynamically, and if the parameter is fixed, an exception is added.
As an example:
1 //Create a ListView object2ListView MYLV =NewListView ( This);3 //the data to display4string[] str =NewString[] {"Hello", "World"};5 //Create Adapter6Arrayadapter Arrayadapter =NewArrayadapter<string>(7 This,8 Android. R.layout.simple_expandable_list_item_1,9 str);Ten Mylv.setadapter (arrayadapter); One Setcontentview (MYLV); A - //this.arrayAdapter.add ("!");
This also shows the ListView, but if you want to add data dynamically, an exception occurs because the string array, str, is a fixed-length array that cannot dynamically add a string, or the code on line 13th will run with an error. So it is recommended to use the list class because he can add data dynamically.
Note the Add () method of Arrayadapter