PopupMenu在不检查所选复选框项目的情况下解除

时间:2014-03-19 18:51:38

标签: android

当我点击我的Popupmenu项目时,项目没有被检查,菜单立即消失。有没有办法检查项目?

PopupMenu popup = new PopupMenu(getActivity(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.filtering_menu, popup.getMenu());
popup.getMenu().findItem(R.id.filter_old).setChecked(hide_old);
popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        Toast.makeText(getActivity(), item.getTitle(), Toast.LENGTH_SHORT).show();
        return false;
    }
});
popup.show();

1 个答案:

答案 0 :(得分:0)

通过发布这个问题,我得到了答案,我只需要在点击事件后自己检查项目:

item.setChecked(!item.isChecked());