listView = (ListView) findViewById(R.id.list_main); /* String[] strings = {"A","A","A","A","A","A","A","A","A"}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_ctn, strings);*/ List<Map<String, Object>> arrayList = new ArrayList<Map<String, Object>>(); Map<String, Object> map = null; int i = 0; while (i<10) { map = new HashMap<String, Object>(); map.put("name", "zh"+i); map.put("age", i); arrayList.add(map); i++; } String[] from = {"name", "age"}; int[] to = {R.id.list_ctn_name, R.id.list_ctn_age}; SimpleAdapter adapter = new SimpleAdapter(this, arrayList, R.layout.list_ctn, from, to); listView.setAdapter(adapter);
<ListView
android:id="@+id/list_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/list_ctn_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView" /> <TextView android:id="@+id/list_ctn_age" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView" /> </LinearLayout>