次の FragmentActivity があります。
public class TabsActivity extends FragmentActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("Home").setIndicator("Home", getResources().getDrawable(R.drawable.hometab)),HomeTab.class, null);
mTabHost.addTab(mTabHost.newTabSpec("Explore").setIndicator("Explore", getResources().getDrawable(R.drawable.exploretab)),ExploreTab.class, null);
mTabHost.addTab(mTabHost.newTabSpec("Info").setIndicator("Info", getResources().getDrawable(R.drawable.infotab)),InfoTab.class, null);
mTabHost.addTab(mTabHost.newTabSpec("Social").setIndicator("Social", getResources().getDrawable(R.drawable.socialtab)),SocialTab.class, null);
mTabHost.addTab(mTabHost.newTabSpec("Contact").setIndicator("Contact", getResources().getDrawable(R.drawable.contacttab)),ContactTab.class, null);
TabWidget tabWidget = mTabHost.getTabWidget();
tabWidget.setStripEnabled(false);
for(int i=0; i < tabWidget.getChildCount(); i++){
tabWidget.getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
TextView tv = (TextView)tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColor(R.color.white));
}
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
Log.d("PAUL",tabId);
if(tabId=="Home"){
finish();
}
TabWidget tw = mTabHost.getTabWidget();
for(int i=0; i < tw.getChildCount(); i++){
TextView tabText = (TextView)tw.getChildAt(i).findViewById(android.R.id.title);
if(tabText.getText()==tabId){
tabText.setTextColor(TabsActivity.this.getResources().getColor(R.color.tcmgreen));
} else {
tabText.setTextColor(TabsActivity.this.getResources().getColor(R.color.white));
}
}
}
});
Intent intent = getIntent();
String tag = intent.getStringExtra("tab");
Log.d("DEBUG",tag);
mTabHost.setCurrentTabByTag(tag);
}
}
ユーザーが [Explore] タブをタップすると、次のエラーが表示されます:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
これが私の ExploreTab クラスです:
public class ExploreTab extends Fragment {
private ArrayList<Level> levels;
private TCMSQLiteHelper sqliteHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
sqliteHelper = new TCMSQLiteHelper(this.getActivity());
levels = sqliteHelper.getAllLevels();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d("DEBUG","Explore Created");
View v = inflater.inflate(R.layout.explorelist, container);
return v;
}
}
ビューが既に読み込まれているという問題がどこにあるのかがわからないため、これは私には意味がありません。ここで何が欠けていますか?