我正在按照官方指南使用这样的上下文操作模式:
listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.shelf_context, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// some processing...
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
}
});
我的 listView 在 aFragment
里面ViewPager
,所以我想在片段变得不可见时隐藏上下文操作栏。但是我该怎么做呢?我打电话listView.clearChoices()
清除选择,但 CAB 仍然可见:
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (!isVisibleToUser) {
listView.clearChoices(); // CAB is still visible.
}
}