2012-10-10 67 views
2

我在FragmentTabs Demo中使用帶有FragmentTabs的ActionBarSherlock。 如何從我的TabHost打開不同的FragmentTab時關閉ActionMode。如何關閉更改上的ActionMode FragmentTab

問候 derjens

鏈接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(); 
    } 
+0

你有一些示例代碼來證明情況? – VKen

+1

編輯我的問題;) – derjens

+0

歡迎來到Stackoverflow!您的編輯將有助於他人更好地瞭解您的情況,以回答您的問題。祝你好運! – VKen

回答

0

您可以通過調用addOnPageChangeListener這樣 viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout){ @Override public void onPageScrollStateChanged(int state) { if(ActionModeController.mActionMode != null) ActionModeController.mActionMode.finish(); } });關閉actionmode