为什么我点击了控件没有东西显示出来
package com.demo.adapter;
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.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class MainActivity extends Activity implements OnItemClickListener {
private ListView listView;
private ArrayAdapter<String> arrayAdapter;
private SimpleAdapter simpleAdapter;
private List<Map<String, Object>> dataList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView1);
/**
* 1.创建1个数组适配器,并加载数据源
* new ArrayAdapter<String>(上下文, 当前ListView加载的每一个列表所对应的布局文件(android.R.layout.simple_list_item_1), 数据源)
* 2.ListView加载适配器
*/
String array_data[] = {"数据源1","数据源2","数据源3","数据源4","数据源5"};
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array_data);
/**1创建适配器,先加上下文,布局文件,绑定布局文件ID,from,最后添加数据源
* new SimpleAdapter(this, data, resource, from, to)
* context:上下文
* data:数据源,一个 List<? extends Map<String, ?>> data多个map所组合成的list集合
* 每一个Map对应ListView列表中的一行
* 每一个Map(键-值对)中的键必须包含所有在from中所指定的键
* resource:列表项的布局的文件ID
* from:Map中的键名
* to:绑定数据视图中的ID,与from成对应关系
* 2.ListView加载适配器
*/
dataList = new ArrayList<Map<String,Object>>();
simpleAdapter = new SimpleAdapter(this, getData(), R.layout.item, new String[] {"imageView", "textView"}, new int[]{R.id.imageView, R.id.textView});
// listView.setAdapter(arrayAdapter);
listView.setAdapter(simpleAdapter);
}
private List<Map<String, Object>> getData() {
for (int i = 0; i < 20; i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("imageView", R.drawable.ic_launcher);
map.put("textView", "安卓机器人" + i);
dataList.add(map);
}
return dataList;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
System.out.println(00);
Log.v("tap", "dianjiqian");
//获取点击的位置
String text = listView.getItemAtPosition(position)+"";
//显示方法。参数 上下文, 显示文本, 显示时常
Toast.makeText(this, "position = " + position + "text = " + text, Toast.LENGTH_SHORT).show();
Log.v("tag", "dianjihou");
}
}