Hallo zusammen,
ich hänge jetzt seit insgesamt wohl mehr als 7 Stunden an einem Problem fest:
Ich möchte einem FragmentTabHost einen Tab hinzufügen, undzwar via TabSpec, dessen Inhalt durch eine TabContentFactory bestimmt wird.
Ich bekomme immer folgende Exception: java.lang.IllegalStateException: No tab known for tag CON1, obwohl ich genau diesen Tab gerade erst hinzufügen will.
Hier der Code:
Java
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import de.FragmentTabs.R;
public class ControllerActivity extends FragmentActivity implements
TabContentFactory {
private FragmentTabHost fragTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.controller_activity_layout);
fragTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
fragTabHost.setup(this, getSupportFragmentManager(),
R.id.realtabcontent);
TabSpec ts = fragTabHost.newTabSpec("CON1");
ts.setContent(this);
ts.setIndicator("CON 1");
fragTabHost.addTab(ts);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.controller, menu);
return true;
}
@Override
public View createTabContent(String tag) {
LayoutInflater inflater = LayoutInflater.from(ControllerActivity.this);
View v;
if (tag.startsWith("CON")) {
v = inflater.inflate(R.layout.connection_fragment_layout, null);
return v;
}
return null;
}
}
Alles anzeigen
Ich hoffe, ihr könnt mir helfen, mir gehen langsam die Ideen aus.
Danke im Voraus
PL1994