package com.example.wang.testapp2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestActivity8 extends AppCompatActivity {
ListView lv_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test8);
lv_2=(ListView)findViewById(R.id.lv_2);
//1.数据结合,layout文件
List<Map<String,Object>> lm=new ArrayList<Map<String, Object>>();
Map<String,Object> map=new HashMap<String, Object>();
map.put("img",R.drawable.f1);
map.put("name","美食1");
map.put("content","美食1的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f2);
map.put("name","美食2");
map.put("content","美食2的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f3);
map.put("name","美食3");
map.put("content","美食3的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f4);
map.put("name","美食4");
map.put("content","美食4的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f5);
map.put("name","美食5");
map.put("content","美食5的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f6);
map.put("name","美食6");
map.put("content","美食6的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f7);
map.put("name","美食7");
map.put("content","美食7的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f8);
map.put("name","美食8");
map.put("content","美食8的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f9);
map.put("name","美食9");
map.put("content","美食9的介绍");
lm.add(map);
map=new HashMap<String, Object>();
map.put("img",R.drawable.f10);
map.put("name","美食10");
map.put("content","美食10的介绍");
lm.add(map);
//数组 key的数组
String[] strings={"img","name","content"};
int[] ids={R.id.iv_2,R.id.tv_7,R.id.tv_8};
//2.创建simple
SimpleAdapter simpleAdapter=new SimpleAdapter(this,lm,R.layout.simple_adpter,strings,ids);
//3.绑定
lv_2.setAdapter(simpleAdapter);
}
}