Android Learning Note: ListView Simple and practical--Display text list

Source: Internet
Author: User

Write the following code in the activity:

Final list<string> items = new arraylist<string> (); Set the data to be displayed here because it is an example, so fix write Dead Items.Add ("Item1"), Items.Add ("item2"); Items.Add ("Item3"); ListView ListView = (ListView) Findviewbyid (R.id.listview1); Get a ListView from a layout, or you can dynamically create a listview.setadapter (new arrayadapter<string> (this,android. R.layout.simple_expandable_list_item_1, items));//Association Adapterlistview.setonitemclicklistener (new Onitemclicklistener () {//Set the Response object @overridepublic void Onitemclick (adapterview<?> parent, View) of the entry in the ListView View,//Response method, where view is a TextView object, position is the ordinal of the selected entry, int position, long id) {Toast.maketext (Getapplicationcontext (), Items.get (position), Toast.length_short). Show ();}});

The ListView is to bind data to it by adapter, the simplest adapter is arrayadapter, and its corresponding data is a list of strings. Which Android. R.layout.simple_expandable_list_item_1 is a default display style provided by the system itself.

Android Learning Note: ListView Simple and practical--Display text list

Related Article

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.