의 탭으로 추가 된 단편 교체 : 나는 탭과 같은 일부 조각이 들어있는 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를 어떻게 대체 할 수 있는지 이해할 수 없다는 것입니다. 탭 호스트의 컨테이너를 전달할 때 현재 탭의 어느 탭이 새로운 조각을 포함해야 하는지를 어떻게 지정할 수 있습니까? 물론 이전의 것을 제거/숨겨야합니다.
멋진 답변 http://stackoverflow.com/questions/18120510/dynamically-changing-the-fragments-inside-a-fragment-tab-host/19859871#19859871 –