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