1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin" 10 tools:context="com.hanqi.testapp2.TestActivity8"> 11 12 <ListView 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:id="@+id/lv_2"></ListView> 16 17 </LinearLayout>
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content"> 5 6 <ImageView 7 android:layout_width="70dp" 8 android:layout_height="70dp" 9 android:src="@drawable/f1" 10 android:id="@+id/iv_2"/> 11 12 <LinearLayout 13 android:layout_width="0dp" 14 android:layout_height="match_parent" 15 android:orientation="vertical" 16 android:layout_weight="1" 17 android:layout_marginLeft="20dp" 18 android:gravity="center_vertical"> 19 20 <TextView 21 android:layout_width="match_parent" 22 android:layout_height="wrap_content" 23 android:text="名字=aaa" 24 android:id="@+id/tv_7"/> 25 <TextView 26 android:layout_width="match_parent" 27 android:layout_height="wrap_content" 28 android:text="内容=aaa" 29 android:id="@+id/tv_8"/> 30 31 32 </LinearLayout> 33 34 </LinearLayout>
1 package com.hanqi.testapp2; 2 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.widget.ListView; 6 import android.widget.SimpleAdapter; 7 8 import java.util.ArrayList; 9 import java.util.HashMap; 10 import java.util.List; 11 import java.util.Map; 12 13 public class TestActivity8 extends AppCompatActivity { 14 15 ListView lv_2; 16 17 @Override 18 protected void onCreate(Bundle savedInstanceState) { 19 super.onCreate(savedInstanceState); 20 setContentView(R.layout.activity_test8); 21 22 lv_2 = (ListView)findViewById(R.id.lv_2); 23 24 //1、数据集合 Layout 25 List<Map<String,Object>> lm = new ArrayList<Map<String, Object>>(); 26 27 Map<String,Object> map = new HashMap<String, Object>(); 28 map.put("img",R.drawable.f1); 29 map.put("name","美食1"); 30 map.put("content","美食1的介绍"); 31 32 lm.add(map); 33 34 map = new HashMap<String, Object>(); 35 map.put("img",R.drawable.f2); 36 map.put("name","美食2"); 37 map.put("content","美食2的介绍"); 38 39 lm.add(map); 40 41 42 43 //数组 key的数组 44 String[] strings = {"img","name","content"}; 45 int[] ids = {R.id.iv_2,R.id.tv_7,R.id.tv_8}; 46 47 //2、创建 48 SimpleAdapter simpleAdapter = new SimpleAdapter(this,lm,R.layout.simple_adapter, 49 strings,ids); 50 51 lv_2.setAdapter(simpleAdapter); 52 } 53 }