记下代码,方便以后查看。还没简化代码,仅仅是有界面。一下用到的是SimpleAdapter
首先是xml文件 activity_main.xml
这是总体框架布局文件
View Code
1 26 12 13 19 26 33 40 47 48
另外的xml是ListView布局
View Code
1 27 8 12 2920 28
MainActivity.java
View Code
1 package com.example.change; 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.List; 6 import java.util.Map; 7 8 import android.R.anim; 9 import android.os.Bundle;10 import android.app.Activity;11 import android.app.Dialog;12 import android.view.Menu;13 import android.view.View;14 import android.widget.ArrayAdapter;15 import android.widget.Button;16 import android.widget.ListView;17 import android.widget.SimpleAdapter;18 19 public class MainActivity extends Activity {20 21 @Override22 protected void onCreate(Bundle savedInstanceState) {23 super.onCreate(savedInstanceState);24 setContentView(R.layout.activity_main); 25 /*ListView lvsimple = (ListView)findViewById(R.id.list);26 String item[] = new String [] {"one", "two", "three"}; 27 ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, item);28 lvsimple.setAdapter(adapter);*/29 ListView lvwCustom = (ListView)findViewById(R.id.list); 30 SimpleAdapter adapter = new SimpleAdapter(this, getData(),R.layout.lvw_custom,new String[] {"lvw_custom_name","lvw_custom_description"}, 31 new int[] {R.id.lvw_custom_name, R.id.lvw_custom_description});32 lvwCustom.setAdapter(adapter);33 }34 35 36 //数据37 private List