ImageView On click not firing at the 2nd click

五迷三道 提交于 2019-12-13 04:40:20

问题


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;

        }

    }
});

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" 

        />       

Initial value of f is 1.


回答1:


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.



来源:https://stackoverflow.com/questions/23624198/imageview-on-click-not-firing-at-the-2nd-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!