Android Basics explained-listview_arrayadapter

Source: Internet
Author: User

Haha bo master recently only to broadcast, write some blog to spend time by the way to summarize the knowledge, things are more basic hope to improve each other

--------------------------------------------------------------------------------------------------------------- ----

ListView is a commonly used Android control with a variety of adapter used (Arrayadapter, Sampleadapter, CursorAdapter, and auto to adapter, etc.)

1. Create a new Android app

2. Pull a ListView control into the View interface

 Public classMainactivityextendsActivity {PrivateListView LV;PrivateArraylist<string> Al =NewArraylist<string>(); @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);    SetData (); }    Private voidSetData () {Al.add (A); Al.add ("B"); Al.add (C); Al.add ("D");//Add Datalv= (ListView) Findviewbyid (R.ID.LISTVIEW1);//Building a ListView object from XML with IDArrayadapter<string> aa=NewArrayadapter<string>        ( ThisAndroid. R.layout.simple_list_item_1,al);//building the Adapter objectlv.setadapter (AA); }}

A simple listview will show up.

Android Basics explained-listview_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.