ListView(一)

一、ListView控件

Activity的main.xml布局文件代码:

<ListViewandroid:id="@id/android:list" 

android:layout_width="fill_parent"

android:layout_height="fill_parent">

</ListView>

Activity代码(activity需要继承ListActivity):

super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mItems=new ArrayList<HashMap<String,String>>();

        HashMap<String,String> i1=new HashMap<String,String>();

        i1.put("Name", "guoxu1");

        i1.put("Sex", "男");

        i1.put("Age", "20");

        mItems.add(i1);

        HashMap<String,String> i2=new HashMap<String,String>();

        i2.put("Name", "guoxu2");

        i2.put("Sex", "男");

        i2.put("Age", "20");

        mItems.add(i2);

        HashMap<String,String> i3=new HashMap<String,String>();

        i3.put("Name", "guoxu3");

        i3.put("Sex", "男");

        i3.put("Age", "20");

        mItems.add(i1);

        //增加头部        this.getListView().addHeaderView(this.getLayoutInflater().inflate(R.layout.headnull), nullfalse);

      String[] mCloumns={"Name","Sex","Age"};//该数组指明了list中的key

      int[] mView={R.id.name,R.id.sex,R.id.age};//该数组指明了布局文件中的id

 ListAdapter adapter=new SimpleAdapter(ListViewDemo.this,mItems,R.layout.rowui,mCloumns,mView);

        setListAdapter(adapter);

posted @ 2011-08-29 22:57  rorshach  阅读(119)  评论(0编辑  收藏  举报