Note the Add () method of Arrayadapter

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.