以顯示注冊信息為例:
一、創建帶有ListView的Activity要繼承ListActivity
this.setContentView(R.layout.user);
二、ListActivity的布局文件user.xml
<ListView
Android:id="@id/android:list"
andoid:scrollbars="vertical"
android:drawSelectorOnTop="false">
三、使用intent獲得用戶保存的信息
Intent intent = getIntent();
String username = intent.getStringExtra("username");
四 、創建要顯示的list內容
HashMap<String,String> map1 = new HashMap<String,String>();
..
map1.put("user_key","姓名");
map 1.put("user_value",username);
...
//對數組進行拆分
String hob = "";
for(String h:hobby){
hob += h=" ";
}
List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
list.add(map1);
...
五、設置適配器
設置list.xml布局文件;
指定list控件
SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list,
new String[]{"user_key","user_value"},
new int[]{R.id.userkey,R.id.uservlaue}
);
setListAdapter(adapter);