ImageView的在用户点击在第2点击不触发 [英] ImageView On click not firing at the 2nd click

查看:170
本文介绍了ImageView的在用户点击在第2点击不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想结束在点击一个imageview.But它不工作的弹出式菜单。

I want to close a popup menu on clicking a imageview.But it is not working.

menuicon.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

        if (f == 1) {
            f = 0;
            mPopupMenu.setContentWidth(ContactsActivity.this.getWindowManager()
                .getDefaultDisplay()
                .getWidth() / 2);
            mAdapter.notifyDataSetChanged();
            mPopupMenu.setAnchorView(menuicon);
            mPopupMenu.show();

        } else {
            mPopupMenu.dismiss();
            f = 1;

        }

    }
});

当我点击menuicon第一时间弹出菜单显示correctly.But当我点击第2次的菜单没有closing.I调试我的code,发现ImageView的实际上是不点火鱼子第二次.menuicon是imageview.And这里是XML code:

When I click the menuicon first time the popup menu is displaying correctly.But when i click for the 2nd time the menu is not closing.I debugged my code and found that the imageview is actually not firing roe 2nd time.menuicon is an imageview.And here is xml code:

<ImageView
            android:id="@+id/menuicon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:src="@drawable/menuicon"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp" 

        />       

的F初始值为1。

Initial value of f is 1.

推荐答案

您需要调用setModal mPopupMenu的(假)。它会调用setFocusable内PopupWindow,并让你得到事件的背景窗口。

You need to call setModal(false) of mPopupMenu. It will call setFocusable of inner PopupWindow and allow you to get events in the background window.

这篇关于ImageView的在用户点击在第2点击不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆