为什么我的程序无法点击
package com.example.listview;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
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>aar_adapter;
private SimpleAdapter simp_adapter;
private List<Map<String,Object>>datalist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[]arr_data={"慕课网1","慕课网2","慕课网3","慕课网4","慕课网5","慕课网6"};
listView=(ListView) findViewById(R.id.listView);
//Adapter(上下文,当前ListView加载的每一个列表项所对应的布局文件,数据源)
//SimpleAdapter
/*
*context:上下文
*data:数据源 List<? extends Map<String, ?>> data)一个Map所组成的List集合
*每一个Map都会对应ListView列表中的一行
*每一个Map(键-值对)的键必修包含所有在from中所指定的键
*resource:列表下的布局文件ID
*from:Map中的键名
*to:绑定数据视图中的Id
*/
datalist=new ArrayList<Map<String,Object>>();
aar_adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arr_data);
//listView.setAdapter(aar_adapter);
simp_adapter=new SimpleAdapter(this, getData(), R.layout.item, new String[]{"image","text"}, new int[]{R.id.image,R.id.text});
listView.setAdapter(simp_adapter);
listView.setOnItemClickListener(this);
}
public List<Map<String,Object>> getData()
{
for(int i=1;i<20;i++)
{
Map<String, Object>map=new HashMap<String, Object>();
map.put("image", R.drawable.ic_launcher);
map.put("text", "慕课网"+(i+1));
datalist.add(map);
}
return datalist;
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String text=listView.getItemAtPosition(arg2)+"";
Toast.makeText(this, "position="+arg2+" text="+text, 1).show();
}
}