如何使用弹出复选框并关闭?

时间:2016-11-08 13:43:10

标签: android popup android-checkbox popupmenu

我筋疲力尽。我尝试选择我的复选框,但弹出窗口总是在我的更改后关闭。当我搜索有关此问题的信息时,我找到了这些链接:

1)PopupMenu dismiss without checking the selected checkbox item

2)How to prevent popup menu from closing on checkbox click

3)Menu item click hides popup

这些都没有帮助我解决我的问题。这是我的代码:

    private void openPopupMenu(View view) {
    final PopupMenu popupMenu = new PopupMenu(this, view);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()){
                case R.id.popup_push:
                    item.setChecked(!item.isChecked());
                    Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
                case R.id.popup_delete_store:
                    Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
            }
            return true;
        }
    });
    popupMenu.inflate(R.menu.activity_stores_popup_menu);
    popupMenu.show();
}

0 个答案:

没有答案