Вопрос

I am working on the tabhost and fragment implementation. There are 5 tabs in my tabhost , I would like to implement some code (go back 1 level) whenever the user leave the tab3. However, I tried on detach and on pause , both are not working.

@Override
public void onDetach() {
    // TODO Auto-generated method stub
           getFragmentManager().popBackStackImmediate();
    super.onDetach();
}

So I wonder what is the activity cycle the fragment will at when the user click on the other tab? or , are there any way to capture that event ? Thanks

Это было полезно?

Решение

Try adding this callback to your TabHost:

myTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener()
{

  @Override
  public void onTabChanged(String tabId)
  {
     // Tab was changed; now do stuff  
  }

});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top