列表显示数据——list

 //创建ListView

ListView listView = new ListView(this);

       //利用系统的layout显示一项

       //data 为:ArrayList(Map<String,Object>)

//R.layout.list_itemlist_item.xml里面有mview1mview2mview3

       SimpleAdapter adapter = new SimpleAdapter(this, data,

              R.layout.list_item, new String[] {"姓名", "性别","年龄"},

              new int[] { R.id.mview1,R.id.mview2,R.id.mview3 });

       //设置数据适配器(绑定数据)

       listView.setAdapter(adapter);

       //启用listView

       setContentView(listView);

       //创建单击列表事件

       OnItemClickListener listener = new OnItemClickListener() {

           public void onItemClick(AdapterView<?> parent, View view,

                  int position, long id) {

           setTitle(parent.getItemAtPosition(position).toString());

           }

       };

    listView.setOnItemClickListener(listener);    //注册单击列表事件

 

 

列表显示数据——list

 

你可能感兴趣的:(list)