0

我在弹出菜单中有一个列表视图,它显示正确,但 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

                }

            });

我找不到解决方案

4

1 回答 1

0

创建您自己的扩展 BaseAdapter 的适配器类。在那里你会找到getView()方法。在那里实现 onClick 方法,它将起作用。

不要用这个,

final ArrayAdapter<String> popadapter = new ArrayAdapter<String>(this,
              android.R.layout.simple_list_item_1, pop);
于 2013-09-10T10:56:34.573 回答