我在弹出菜单中有一个列表视图,它显示正确但是onitemclicklistener不适用于该列表视图。
public String[] pop={"a","b","c","d"};
我的适配器
final ArrayAdapter<String> popadapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pop);
public void onClick(View v) {
popUpView = getLayoutInflater().inflate(R.layout.popup,
null); // inflating popup layout
mpopup = new PopupWindow(popUpView, 250, 140);
mpopup.setAnimationStyle(android.R.style.Animation_Dialog);
mpopup.showAtLocation(popUpView, Gravity.CENTER, 0, 0);
mpopup.setTouchable(true);
mpopup.setFocusable(true);
mpopup.setOutsideTouchable(true);
mpopup.setContentView(popUpView);
ListView lv=(ListView)popUpView.findViewById(R.id.listView1);
lv.setAdapter(popadapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
mpopup.dismiss();
Toast.makeText(getApplicationContext(),
"ok", Toast.LENGTH_SHORT)
.show();
// TODO Auto-generated method stub
}
});
我找不到解决方案
答案 0 :(得分:0)
创建自己的扩展BaseAdapter的适配器类。在那里你会找到 getView()方法。在那里实现onClick方法,它将起作用。
不要使用它,
final ArrayAdapter<String> popadapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pop);