ListView implements a simple list and listview implements

Source: Internet
Author: User

ListView implements a simple list and listview implements
Simple list of ListView implementations

:

ListView sheets that have nothing to do are as follows:

Fry. Activity01

1 package fry; 2 3 import com. example. listView. r; 4 5 import android. app. activity; 6 import android. OS. bundle; 7 import android. view. view; 8 import android. widget. adapterView; 9 import android. widget. adapterView. onItemClickListener; 10 import android. widget. arrayAdapter; 11 import android. widget. listView; 12 import android. widget. toast; 13 14 public class Activity01 extends Activity implements OnItemCl IckListener {15 private ListView listView; 16 @ Override17 protected void onCreate (Bundle savedInstanceState) {18 // TODO Auto-generated method stub19 super. onCreate (savedInstanceState); 20 setContentView (R. layout. activity01); 21 listView = (ListView) findViewById (R. id. listView); 22 ArrayAdapter <String> adapter = new ArrayAdapter <String> (this, android. r. layout. simple_expandable_list_item_1, getData (); 23 li StView. setAdapter (adapter); 24 listView. setOnItemClickListener (this); 25} 26 @ Override27 public void onItemClick (AdapterView <?> Parent, View view, int position, 28 long id) {29 // TODO Auto-generated method stub30 String string = (String) parent. getItemAtPosition (position); 31 32 Toast. makeText (this, string, Toast. LENGTH_SHORT ). show (); 33} 34 35 private String [] getData () {36 return new String [] {"Han", "Cai Jing", "Lu benwei ", "wuwukai", "Wolf 2", "Brother Chaoyang", "Hongqiao yijie", "sharp brother", "Wang baoqing", 37 "series ", "fool", "Zhang San", "Li Si", "Wang Wu" };38} 39}

/ListView/res/layout/activity01.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="vertical" > 6  7     <ListView  8         android:id="@+id/listView" 9         android:layout_width="match_parent"10         android:layout_height="wrap_content"11         ></ListView>12 13 </LinearLayout>

 

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.