simpleView显示不出来
package com.example.newandroid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
private ListView listView;
private ArrayAdapter<String>arr_adapter;
private SimpleAdapter sim_adapter;
private List<Map<String,Object>> data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView=(ListView) findViewById(R.id.listView);
//1.新建适配器
//ArrayAdapter(上下文,当前listView加载的每一个列表项对应的布局文件,数据源)
//2.适配器加载数据源
String[] arr_data={"obj1","obj2"};
arr_adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arr_data);
/**
* ocntext:上下文
* date:数据源(List<?extends Map<String,?>> data) 一个map所组成的集合
* 每一个Map都会去对应ListView列表中的一行
* 每一个Map(键-值对)中的键必须包含所有在form中所有的键
* resource:列表项的布局文件ID
* form:Map中的键名
* to:绑定数据视图中的ID,与form成对应关系
*/
data=new ArrayList<Map<String,Object>>();
sim_adapter=new SimpleAdapter(MainActivity.this, data, R.layout.item, new String[]{"pic","text"}, new int[]{R.id.pic,R.id.text});
//3.视图加载适配器
//listView.setAdapter(arr_adapter);
listView.setAdapter(sim_adapter);
}
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", "obj"+i);
data.add(map);
}
System.out.println("123");
return data;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}