ListView 中使用SimpleAdapter lv.setOnItemClickListener(new MyOnItemClickListener());再加上这样一个事件监听 为什么会没反应?listviewsimpleadapter
解决方案 »
- ListView 焦点移动
- 求助~android修改了R.java的根目录名字,布局xml出错了
- 安卓配置问题 连不上adb.exe
- android 从手机相册中取出图片后,随意摆放在屏幕上,如何实现
- android 按钮转换成普通的按钮
- android 加载图片渐变效果
- jxl.jar读取excel 并存到sqlite,logcat提示 couldnot find jxl.workbook.getworkbook
- android 多线程问题,为什么我这个程序会CRASH
- Android 自定义LinearLayout标题栏,照着郭霖大神的书,结果进程序时就闪退,附上代码。
- 求问安卓toast
- 现在googlemap v1的apikey已经不能申请了,v2的怎么申请呢
- 请教个关于dlna镜像传输的问题
看看这篇文章,比较基础
http://blog.csdn.net/fs1360472174/article/details/8822719
lv.setOnItemClickListener(new MyOnItemClickListener());class MyOnItemClickListener implements OnItemClickListener{ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
System.out.println(arg0);
System.out.println(arg1);
System.out.println(arg2);
System.out.println(arg3);
}
}但是不论你怎么点 都不会有反应的 控制台不会输出任何东西
import java.util.Map;
import java.util.Vector;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;public class SimpleAdapterActivity extends Activity {
class MyOnItemClickListener implements OnItemClickListener{ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
System.out.println(arg0);
System.out.println(arg1);
System.out.println(arg2);
System.out.println(arg3);
}
} protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); ListView lv = new ListView(this);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); String[] names = { "小明", "小红", "小强", "小花", "小刚" };
String[] dels = { "删除1", "删除2", "删除3", "删除4", "删除5" };
String[] upds = { "修改1", "修改2", "修改3", "修改4", "修改5" }; Vector<Map<String, Object>> v = new Vector(); for (int i = 0; i < names.length; i++) {
HashMap map = new HashMap();
map.put("stuName", names[i]);
map.put("dels", dels[i]);
map.put("upds", upds[i]);
v.add(map);
} SimpleAdapter adapter = new SimpleAdapter(this, v,
R.layout.simple_list_item, new String[] { "stuName", "dels",
"upds" }, new int[] { R.id.text_names,
R.id.button_dels, R.id.button_upds });
lv.setAdapter(adapter);
lv.setOnItemClickListener(new MyOnItemClickListener()); LinearLayout line = new LinearLayout(this);
line.setOrientation(LinearLayout.VERTICAL); Button b = new Button(this);
b.setText("添加"); line.addView(b);
line.addView(lv); this.setContentView(line); }
}