-1
주 FragmentActivity에서 TabHost를 사용하는 새로운 FragmentActivity를 표시하는 샘플 코드를 얻고 싶습니다. FragmentActivity는 5 개의 탭으로 구성되며 탭 중 하나에는 탭이있는 새 활동이 표시되어야합니다. 내 코드 : 다른TabHost에서 탭으로 단편화 작업
TabHost.OnTabChangeListener tabChangeListener = new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
fm = getSupportFragmentManager();
venueFragment = (FragmentVenue) fm.findFragmentByTag("venue");
favoriteFragment = (FragmentFavorite) fm.findFragmentByTag("favorite");
venueTrendingFragment = (FragmentVenueTrending) fm.findFragmentByTag("venuetrendingnow");
searchFragment = (FragmentSearch) fm.findFragmentByTag("search");
accountFragment = (FragmentAccount) fm.findFragmentByTag("account");
android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
/** Detaches the venueFragment if exists */
if(venueFragment!=null)
ft.detach(venueFragment);
/** Detaches the favoriteFragment if exists */
if(favoriteFragment!=null)
ft.detach(favoriteFragment);
/** Detaches the venueTrendingFragment if exists */
if(venueTrendingFragment!=null)
ft.detach(venueTrendingFragment);
/** Detaches the searchFragment if exists */
if(searchFragment!=null)
ft.detach(searchFragment);
if(accountFragment!=null)
ft.detach(accountFragment);
/** If current tab is venue */
if(tabId.equalsIgnoreCase("venue")){
if(venueFragment==null){
/** Create venueFragment and adding to fragment transaction */
ft.add(R.id.realtabcontent,new FragmentVenue(), "venue");
}else{
/** Bring to the front, if already exists in the fragment transaction */
ft.attach(venueFragment);
}
}else if(tabId.equalsIgnoreCase("favorite")){ /** If current tab is favorite */
if(favoriteFragment==null){
/** Create favoriteFragment and adding to fragment transaction */
ft.add(R.id.realtabcontent,new FragmentFavorite(), "favorite");
}else{
/** Bring to the front, if already exists in the fragment transaction */
ft.attach(favoriteFragment);
}
}else if(tabId.equalsIgnoreCase("venuetrendingnow")){ /** If current tab is venueTrendingFragment */
if(venueTrendingFragment==null){
/** Create venueTrendingFragment and adding to fragment transaction */
ft.add(R.id.realtabcontent,new FragmentVenueTrending(), "venuetrendingnow");
}else{
/** Bring to the front, if already exists in the fragment transaction */
ft.attach(venueTrendingFragment);
}
}else if(tabId.equalsIgnoreCase("search")){ /** If current tab is searchFragment */
if(searchFragment==null){
/** Create searchFragment and adding to fragment transaction */
//ft.add(R.id.realtabcontent,new FragmentSearch(MainActivity.this), "search");
//Intent intent = new Intent(this,SecondTabhost.class);
Intent intent = new Intent(MainActivity.this, SecondTabhost.class);
startActivity(intent);
}else{
/** Bring to the front, if already exists in the fragment transaction */
//ft.attach(searchFragment);
Intent intent = new Intent(MainActivity.this, SecondTabhost.class);
startActivity(intent);
}
}else if(tabId.equalsIgnoreCase("account")){ /** If current tab is accountFragment */
if(accountFragment==null){
/** Create accountFragment and adding to fragment transaction */
ft.add(R.id.realtabcontent,new FragmentAccount(), "account");
}else{
/** Bring to the front, if already exists in the fragment transaction */
ft.attach(accountFragment);
}
}
ft.commit();
}
};
내부 경우 (tabId.equalsIgnoreCase는 ("검색")) 내가 다음 FragmentActivity 가진 tabhost를 표시하는 지연 있도록 다음 활동으로 이동하는 의도를 사용하는 위의 코드이다. 지연없이 활동을 표시하고 싶습니다.
그래서 TEH 문제가 : MainActivity.onCreate에서 는 어댑터에
사용하여 각 탭을 추가? –
새로운 FragmentActivity를 탭에 추가하는 코드를 얻고 싶습니다. –
[FAQ를 읽어야합니다.] (http://stackoverflow.com/faq) 그들은 여기에서 질문하는 방법과 질문 할 질문을 더 잘 이해할 수 있도록 도와줍니다. – adneal