2013-01-24 3 views
3

의 탭으로 추가 된 단편 교체 : 나는 탭과 같은 일부 조각이 들어있는 TabHost를내 안드로이드 응용 프로그램과 함께 다음과 같은 문제가있어 tabhost

합니다. 이러한 단편은 프로그래밍 방식으로 추가되었습니다. 이제 탭의 내용을 다른 Fragment로 바꾸고 싶습니다. 그리고 그 방법을 모르겠습니다. 내가 found XML을 통해 추가 된 조각을 대체하는 방법,하지만 그게 내가 뭘 하려는지 아니에요.

미리 제안 해 주셔서 감사합니다.

편집 :

private void initialiseTabHost(Bundle args) { 
    mTabHost = (TabHost)findViewById(android.R.id.tabhost); 
    mTabHost.setup(); 

    addUserListTab(args); 
    //methods to add other tabs 


    mTabHost.setOnTabChangedListener(this); 
} 

private void addUserListTab(Bundle args){ 
    TabInfo tabInfo = null; 
    LayoutParams tabIconParams = new LayoutParams(200, 110); 
    tabIconParams.setMargins(0, 0, 0, 0); 
    View userIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator,mTabHost, false); 
    ImageView userIcon = (ImageView) userIndicator.findViewById(R.id.tab_icon); 
    userIcon.setLayoutParams(tabIconParams); 
    TabSpec specUser = mTabHost.newTabSpec("user"); 
    specUser.setIndicator(userIndicator); 
    userIcon.setImageDrawable(getResources().getDrawable(R.drawable.selector_user)); 
    userIcon.setScaleType(ImageView.ScaleType.FIT_CENTER); 

    AddTab(this, this.mTabHost, specUser, (tabInfo = new TabInfo("user", ListUserFragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 

} 
private static void AddTab(MainActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { 
    // Attach a Tab view factory to the spec 
    tabSpec.setContent(activity.new TabFactory(activity)); 
    tabHost.addTab(tabSpec); 
} 

: 요청 된 소스 (단지 관련 부분, 이상이 필요한 경우 말씀 해주십시오)

나는 tabhost를 초기화하고 프로그램 탭/조각을 추가 할 수있는 방법이 문제는 프로그래밍 방식으로 tabhost에 추가 한 ListUserFragment를 어떻게 대체 할 수 있는지 이해할 수 없다는 것입니다. 탭 호스트의 컨테이너를 전달할 때 현재 탭의 어느 탭이 새로운 조각을 포함해야 하는지를 어떻게 지정할 수 있습니까? 물론 이전의 것을 제거/숨겨야합니다.

+0

멋진 답변 http://stackoverflow.com/questions/18120510/dynamically-changing-the-fragments-inside-a-fragment-tab-host/19859871#19859871 –

답변

1

Fragment을 다른 것으로 바꾸려면 FragmentManager을 가져오고 FragmentTransaction을 시작해야합니다.

getFragmentManager().beginTransaction().replace(R.id.container, new Fragment()).commit(); 

공식 fragment guide.도 읽어야합니다.

+1

이것은 파편을 대체하는 데는 효과가없는 것 같습니다. 프로그래밍 방식으로 추가되었습니다. R.id. 컨테이너는 프래그먼트를 추가 한 이후에 가지고 있지 않은 이전 프래그먼트의 컨테이너를 설명하며 프래그먼트를 TabHost의 부모로 프로그래밍 방식으로 설명합니다. – soriak

+0

모든 종류의 단편에 대해 작동합니다. 프로젝트의 출처를 알려주십시오. – Leandros

+0

EDIT에서 내 소스의 관련 부분을 제공했습니다. 더 이상 필요하다면 알려주세요. 내 문제를 설명하기에 충분할 것으로 기대합니다. 미리 감사드립니다 – soriak

관련 문제