我在 FragmentTabs 演示中将 ActionBarSherlock 与 FragmentTabs 一起使用。从我的 TabHost 打开不同的 FragmentTab 时如何关闭 ActionMode。
问候德仁
链接到 ActionBarSherlock 演示:FragmentTab.java / Tab LoaderCursorSupport.java
这里是我的 ActionMode 中的代码:
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
selectedRowId = id;
mMode = ((SherlockFragmentActivity) getActivity()).startActionMode(new TodoActionMode());
}
private final class TodoActionMode implements ActionMode.Callback {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
boolean isLight = DashboardActivity.THEME == R.style.Theme_Sherlock_Light;
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.todo_actionmode_menu, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_todo_actionmode_remove:
eintragLoeschen(selectedRowId);
return true;
case R.id.menu_todo_actionmode_new:
neuerTask();
return true;
default:
mMode.finish();
return true;
}
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mMode = null;
}
}
private void eintragLoeschen(final long rowId) {
//eigenen dialog erstellen
final Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.projekttab_todolist_task_delete_dialog);
dialog.setTitle(R.string.task_wirklich_loeschen_title);
//OK und Abbrechen Button zuweisen
Button dialogButtonAbbrechen = (Button) dialog.findViewById(R.id.button_abbrechen);
Button dialogButtonOk = (Button) dialog.findViewById(R.id.button_ok);
//wenn Button Abbrechen gedrueckt wurde
dialogButtonAbbrechen.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss(); //schliese dialog
}
});
//wenn Button Ok gedrueckt wurde
dialogButtonOk.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//TODO Eintrag Löschen auf ArrayAdapter ändern
Uri uri = ContentUris.withAppendedId(TodoTable.CONTENT_URI, todolist.get((int) rowId).getId());
getActivity().getContentResolver().delete(uri, null, null);
mAdapter.remove(todolist.get((int) rowId));
mAdapter.notifyDataSetChanged();
mMode.finish();
dialog.dismiss();
}
});
//zeige dialog
dialog.show();
}