@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listview = (ListView) findViewById(R.id.listView1);
//新建一个适配器
//适配器加载数据源
String[] arr={"zz1","zz2","zz3","zz4","zz5",};
datalist = new ArrayList<Map<String,Object>>();
arradapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arr);
simadapter = new SimpleAdapter(this, getData(), R.layout.item, new String[]{"pic","textview"}, new int[]{R.id.pic,R.id.tv});
//3:视图(Listview)加载适配器器
//listview.setAdapter(arradapter); //设置数组适配器
listview.setAdapter(simadapter); //设置简单适配器
}
private List<Map<String,Object>> getData(){
for(int i =0;i<20;i++){
Map<String,Object>map = new HashMap<String,Object>();
map.put("pic",R.drawable.ic_launcher);
map.put("text", "你好"+i);
datalist.add(map);
}
return datalist;
}
D_punto
相关分类