继承ListActivity就可以不用setContentView,Android也会自动帮我们构造出一个全屏的列表。

public class SettingActivity extends ListActivity {private static String[] allTest = new String[]{"CPU测试","LCD测试",        "Battery测试",        "Backlight测试",        "PhoneCall测试",        "Vibrator测试",        "Flashlight测试",        "BT测试",        "Audio测试",        "Memory测试",        "Video测试",        "OpenGL测试",     };private static int[] icon = new int[]{R.drawable.cpu,R.drawable.lcd,R.drawable.connectivity,R.drawable.battery,R.drawable.call,R.drawable.video,R.drawable.fm,R.drawable.bt,R.drawable.audio,R.drawable.memory,R.drawable.pbook,R.drawable.mmc};@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);/** * 一个map对应列表中的一项数据 */List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();//初始化列表项需要显示的内容for (int i = 0; i < allTest.length; i++) {Map<String, Object> item = new HashMap<String, Object>();item.put("image", icon[i]);item.put("textview", allTest[i]);dataList.add(item);}// 构建适配器Adapter,将数据与显示数据的布局页面绑定SimpleAdapter simpleAdapter = new SimpleAdapter(this, dataList,R.layout.list_item, new String[] { "textview", "image" },new int[] { R.id.text_name, R.id.image});// 通过setAdapter()方法把适配器设置给ListViewsetListAdapter(simpleAdapter);}@Overrideprotected void onListItemClick(ListView l, View v, int position, long id) {// TODO Auto-generated method stub//列表项单击事件super.onListItemClick(l, v, position, id);}}

更多相关文章

  1. [Android]单元测试实例
  2. 3D相册图片滑动+倾斜+放大+倒影处理
  3. android ListView内容无限循环显示
  4. Android(安卓)在Fragment 中控制 Activity 的控件隐藏和显示
  5. android AIDL实践之清理应用缓存
  6. Android(安卓)中Scroll中添加ListView
  7. Android列表分页功能的实现,往下拉时刷新数据(显示正在加载中)
  8. Android之SQLite数据库的使用
  9. Android通过URL获取网络数据(2)

随机推荐

  1. 调用C++底层 Thread & Mutex 的注意事项
  2. Android(安卓)之 事件
  3. Android(安卓)Makefile中 如何识别 TARGE
  4. Android(安卓)Toolchain与Bionic Libc
  5. Android(安卓)加速度传感器(G-Sensor)
  6. android sdk manager 无法下载
  7. Android中RelativeLayout各个属性的含义
  8. 【转】Android中对json的解析和处理
  9. AspectJ 在 Android(安卓)中的使用
  10. 理解 Android(安卓)Build 系统