Android 批处理上下文操作模式

Android 批处理上下文操作模式,android,android-actionbar,android-actionmode,Android,Android Actionbar,Android Actionmode,我想在longClick()上启用多视图选择。我应该声明一个动作模式对象并调用startActionMode()?另外,我将如何更改单项目单击的菜单列表?我使用文档作为参考,如图所示 ListView listView = getListView(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultiChoic

我想在longClick()上启用多视图选择。我应该声明一个动作模式对象并调用startActionMode()?另外,我将如何更改单项目单击的菜单列表?我使用文档作为参考,如图所示

    ListView listView = getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
                                      long id, boolean checked) {
    // Here you can do something when items are selected/de-selected,
    // such as update the title in the CAB
}

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    // Respond to clicks on the actions in the CAB
    switch (item.getItemId()) {
        case R.id.menu_delete:
            deleteSelectedItems();
            mode.finish(); // Action picked, so close the CAB
            return true;
        default:
            return false;
    }
}

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    // Inflate the menu for the CAB
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.context, menu);
    return true;
}

@Override
public void onDestroyActionMode(ActionMode mode) {
    // Here you can make any necessary updates to the activity when
    // the CAB is removed. By default, selected items are deselected/unchecked.
}

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    // Here you can perform updates to the CAB due to
    // an invalidate() request
    return false;
}

}))

要更改单个项目的菜单列表,请单击下面的代码

int count=0;
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
                                  long id, boolean checked) {
if (checked) {
            count++;
        } else {
            count--;
        }
mode.invalidate();  // Add this to Invalidate CAB so that it calls onPrepareActionMode
}
现在修改onPrepareActionMode,如下所示

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
if (selCount == 1){
   //show the menu here that you want if only 1 item is selected
} else {
  //show the menu here that you want if more than 1 item is selected
       }
}

谢谢,但这就是我如何调用startActionMode()?mActionMode=new UniversityList()。startActionMode(multichoice)的方法,其中mActionMode是ActionMode对象,multichoice是MultiChoiceModelListener对象?