문제

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