main.xml

<?xml version="1.0" encoding="utf-8"?><ListView xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/listView"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" />   

item.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="56dp"  >    <ImageView        android:src="@drawable/ic_launcher"        android:layout_width="48dp"        android:layout_height="48dp"       />    <TableLayout         android:layout_width="0dp"        android:layout_height="wrap_content"       android:layout_weight="1.0"        android:layout_gravity="center_vertical"        android:stretchColumns="0,1"        >        <TableRow >            <TextView android:id="@+id/tv_01"/>            <TextView android:id="@+id/tv_02"/>        </TableRow>        <TableRow >            <TextView android:id="@+id/tv_03"/>            <TextView android:id="@+id/tv_04"/>        </TableRow>            </TableLayout></LinearLayout>

activity

package com.ghg.SimpleAdapter;import java.util.ArrayList;import java.util.HashMap;import java.util.Random;import android.app.Activity;import android.os.Bundle;import android.widget.ListView;import android.widget.SimpleAdapter;public class Day0604_SimpleAdapterActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        initView();    }    //构造数据源,一个存放map集合的ArrayList    ArrayList<HashMap<String, Object>> list;    private   ArrayList<HashMap<String, Object>> getList(){    list=new ArrayList<HashMap<String,Object>>();    for(int i=1;i<=20;i++){    HashMap<String, Object> map=new HashMap<String, Object>();    //姓名,身高(cm),体重(斤),价格(万)    map.put("name", "jiajia"+i);    map.put("height", 160+new Random().nextInt(10));    map.put("weight", 100+new Random().nextInt(10));    map.put("price", 100+new Random().nextInt(200));    list.add(map);    }    return list;        }    ListView listView;private void initView() {// TODO Auto-generated method stublistView=(ListView) findViewById(R.id.listView);String[] from={"name","height","weight","price"};int[] to={R.id.tv_01,R.id.tv_02,R.id.tv_03,R.id.tv_04};SimpleAdapter adapter=new SimpleAdapter(this, getList(), R.layout.item, from, to);listView.setAdapter(adapter);}}




更多相关文章

  1. 学习日记-- Android写文件到SDCard的代码
  2. Android使用WheelView自定义时间选择器弹窗
  3. Android(安卓)Spinner控件详解
  4. Android转战开发Kotlin
  5. android 单例
  6. android 单例
  7. android单元测试
  8. Android(安卓)UI开发(一)初识安卓
  9. android 修改AVD的存放位置

随机推荐

  1. Android中简单的电话管理与短信管理App编
  2. “Nothing to push” error in Android(
  3. Android(安卓)aspectJ Aop
  4. android 源码大全
  5. android 1.6 launcher研究之launcher的左
  6. setTheme问题2
  7. Android(安卓)开发常用的网站
  8. Android(安卓)圆形ProgressBar风格设置
  9. 如何实现像ios那样的富有弹性的ListView
  10. ExifInterface 介绍