Панель действий не обновляется при нажатии «Назад» в BackStack of Nested Fragments?

У меня есть 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();

person Kruti Mevada    schedule 15.09.2014    source источник
comment
транзакция.addToBackStack (нуль);   -  person Digvesh Patel    schedule 15.09.2014
comment
используйте onREsume в основной деятельности вместо basefreagment для обновления фрагмента   -  person raj    schedule 15.09.2014


Ответы (1)


Вам нужно позвонить getActivity().invalidateOptionsMenu(); для обновления вашего optionMenu.

документы говорят: Declare that the options menu has changed, so should be recreated. The onCreateOptionsMenu(Menu) method will be called the next time it needs to be displayed

person Alex Chengalan    schedule 15.09.2014
comment
Спасибо за вашу помощь. Я неправильно реализовывал панель действий. это решило мою проблему. спасибо еще раз - person Kruti Mevada; 16.09.2014