ImageView On click not firing at the 2nd click---part 2

时光毁灭记忆、已成空白 提交于 2020-01-06 05:46:32

问题


I had posted this yeaterday.As you can see the problem was that I am trying to show a context menu and dismiss it using the same button.The previous problem was,when I was clicking the button the menu was showing,but then it was not closing.One of my friend here suggested to change: mPopupMenu.setModal(false); which was true previously.Now the menu is showing and dismissing perfectly on button click.But the new problem is onItemClick of the menu is not working now.Tried a lot but couldnt find a solution.Here is the code:

mPopupMenu = new IcsListPopupWindow(this);
        mAdapter = new PopupMenuAdapter(this, R.layout.popmenu_row/*android.R.layout.simple_list_item_1*/, poparray);
        mPopupMenu.setAdapter(mAdapter);
        mPopupMenu.setModal(false);
        mPopupMenu.setOnItemClickListener(ContactsActivity.this);
         // only if you need it

        menuicon.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


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




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


            }



            }
        });

Here I am showing the button menuicon in actionbar.I am using actionbarsherlock library.


回答1:


You are trying to toggling the mPopupMenu view by using button click. if i am correct try the following code.

menuicon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
              if(mPopupMenu != null){
                if(mPopupMenu.isShowing()){
                  mPopupMenu.dismiss();   
                }else{
                  mPopupMenu.setModal(true);
                  mPopupMenu.setContentWidth(ContactsActivity.this.getWindowManager().getDefaultDisplay().getWidth() / 2);
                  mAdapter.notifyDataSetChanged(); // if you change anything
                 mPopupMenu.setAnchorView(menuicon);
                 mPopupMenu.show();
               }
              }
            }
        });


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

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