У меня есть BaseFragment, который расширяют все остальные фрагменты. А базовый фрагмент OnCreate() добавляет к приложению пользовательскую панель действий. Все дочерние фрагменты обновляют кнопки панели действий и заголовок. При обратном нажатии панель действий не обновляется.
общедоступный абстрактный класс BaseFragment расширяет фрагмент {
public TextView actionbarTextView;
public Button actionbarSettings;
public void updateActionbar(String title, boolean showSettings){
actionbarTextView.setText(title);
actionbarSettings.setvisibility(showSettings ? View.VISIBLE :View.GONE);
}
}
public class ChildFragment1 extends BaseFragment{
@override
onResume(){
updateActionbar("ChildFragment1",false);
}
}
public class ChildFragment2 extends BaseFragment{
@override
onResume(){
updateActionbar("ChildFragment2",true);
}
}
Здесь, когда я получил от childFragment1 -> childFragment2. При обратном нажатии кнопки «Заголовок» и «Панель действий» не обновляются.
Как я могу реализовать его, чтобы он всегда работал? Я заменяю фрагмент, как показано ниже.
Fragment newFragment = new ExampleFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(true);
// Commit the transaction
transaction.commit();