ImageView的在用户点击在第2点击不费一枪---第2部分 [英] ImageView On click not firing at the 2nd click---part 2
问题描述
我已经贴<一个href=\"http://stackoverflow.com/questions/23624198/imageview-on-click-not-firing-at-the-2nd-click\">this yeaterday.As可以看到的问题是,我试图表现出上下文菜单,并使用相同的button.The previous问题,当我点击按钮菜单是显示驳回,但它不是我的朋友closing.One这里建议改变: mPopupMenu.setModal(假);
这是真正
previously.Now的菜单显示和按钮完全驳回click.But新问题 onItemClick
菜单不工作now.Tried了很多,但无法找到一个解决方案。这里是code:
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;
}
}
});
我在这里显示actionbar.I按钮menuicon正在使用 actionbarsherlock库。
推荐答案
您正试图通过切换按钮,使用点击mPopupMenu视图。如果我是正确尝试以下code。
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();
}
}
}
});
这篇关于ImageView的在用户点击在第2点击不费一枪---第2部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!