Android Neue Activity im TabWidget laden

derSoerrn

Aktives Mitglied
Hallo,

ich habe, mal wieder, ein kleines Problem, und zwar würde ich gerne wissen, wie eine neue Activity für ein Tab lade.

Hier mein misslungener Versuch:
Java:
public class Main extends Activity implements TabContentFactory{

	Intent rechner, optionen, hilfe;
	TabHost th;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
        //requestWindowFeature(Window.FEATURE_NO_TITLE);
		//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		setContentView(R.layout.main);
		
		th = (TabHost)findViewById(R.id.TBtest);
		
		rechner = new Intent(getApplicationContext(), Rechner.class);
		optionen = new Intent(getApplicationContext(), Optionen.class);
		hilfe 	 = new Intent(getApplicationContext(), Hilfe.class);
		
		TabSpec ts1 = th.newTabSpec("tab1");
		TabSpec ts2 = th.newTabSpec("tab2");
		TabSpec ts3 = th.newTabSpec("tab3");
		
		ts1.setIndicator("Rechner", getResources().getDrawable(R.drawable.test));
		ts2.setContent(this);
		th.addTab(ts1);
		
		ts2.setIndicator("Hilfe", getResources().getDrawable(R.drawable.test));
		ts2.setContent(this);
		th.addTab(ts2);
		
		ts3.setIndicator("Optionen", getResources().getDrawable(R.drawable.test));
		ts3.setContent(this);
		th.addTab(ts3);
	}
        public View createTabContent(String tag) {
		// TODO Auto-generated method stub
		if(tag.equals("tab1")){
			
		}else if(tag.equals("tab2")){
			
		}else if(tag.equals("tab3")){
			
		}
		return null;
	}

Ich habe ein bisschen gegooglet und herausgefunden, das man die TabContentFactory nehmen sollte. Allerdings ist mir dann aufgefallen, dass ich ein View Element zurückgeben muss, was mir ja soweit ich weiß nicht hilft.

Was kann ich also tun, damit ich meine Intents benutzen kann? Zuerst habe ich diesen Teil so geschrieben:

Java:
                rechner = new Intent(getApplicationContext(), Rechner.class);
		optionen = new Intent(getApplicationContext(), Optionen.class);
		hilfe 	 = new Intent(getApplicationContext(), Hilfe.class);
		
		TabSpec ts1 = th.newTabSpec("tab1");
		TabSpec ts2 = th.newTabSpec("tab2");
		TabSpec ts3 = th.newTabSpec("tab3");
		
		ts1.setIndicator("Rechner", getResources().getDrawable(R.drawable.test));
		ts2.setContent(rechner);
		th.addTab(ts1);
		
		ts2.setIndicator("Hilfe", getResources().getDrawable(R.drawable.test));
		ts2.setContent(hilfe);
		th.addTab(ts2);
		
		ts3.setIndicator("Optionen", getResources().getDrawable(R.drawable.test));
		ts3.setContent(optionen);
		th.addTab(ts3);

So ist die App jedoch immer abgestürzt...

Hoffe ihr könnt mir helfen ;-)
 

schlingel

Gesperrter Benutzer
Das Problem ist wohl, dass Google die Methodik geändert hat. Früher war es so, dass du entweder alles in eine Activity gepackt hast oder die entsprechenden Teile als Activities nachgeladen hast.

Das hat sich jetzt geändert durch die Fragments. Also wenn du die Teile auslagern willst, musst du sie in Fragments und nicht Activities packen.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
J Android App stürzt ab wenn neue activity gestartet Android & Cross-Platform Mobile Apps 6
S Neue Activity lässt sich nicht starten Android & Cross-Platform Mobile Apps 28
E Neue app erstellen Android & Cross-Platform Mobile Apps 3
T Android Android Augmented Faces in Java. Neue Landmarks erstellen Android & Cross-Platform Mobile Apps 1
B Android SQLite Tabelle neue Spalten hinzufügen Android & Cross-Platform Mobile Apps 8
S Android neue Version des Programms wird nicht in Emulator geladen Android & Cross-Platform Mobile Apps 1
J Android neue View mit OnTouchListener Android & Cross-Platform Mobile Apps 0
W JSONARRAY per Intent an andere Activity übergeben und umwandeln ggbf. Android & Cross-Platform Mobile Apps 1
M Activity einer anderen App mit result Android & Cross-Platform Mobile Apps 2
CT9288 Methode von Fragment durch Activity rufen scheitert Android & Cross-Platform Mobile Apps 7
ruutaiokwu Android Daten von "Activity A" nach "Activity B" umleiten? Android & Cross-Platform Mobile Apps 13
L Android Lockscreen-Sperrmuster activity verwenden Android & Cross-Platform Mobile Apps 1
D Android Activity wechseln per Button Android & Cross-Platform Mobile Apps 3
P Android Android-App Crash - Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 2
B Android Activity nach gedrückte Returntaste weiterlaufen lassen Android & Cross-Platform Mobile Apps 2
J Probleme mit ViewPager und Activity Android & Cross-Platform Mobile Apps 1
B Android In einem View der ersten Activity zweite anzeigen Android & Cross-Platform Mobile Apps 2
G Accelerometer ohne Activity Android & Cross-Platform Mobile Apps 8
J Android BroadcastHandler extends BroadcastReceiver; auf Activity zugreifen? Android & Cross-Platform Mobile Apps 5
K Android Übergeordnete Activity herausfinden? Android & Cross-Platform Mobile Apps 7
W Android Designfrage / Layout / Activity / Fragments Android & Cross-Platform Mobile Apps 2
B Login Activity Android & Cross-Platform Mobile Apps 1
M Android Suche Activity/View Namen Android & Cross-Platform Mobile Apps 1
K Unbekannte Menge von Daten (Strings oder Ints) an Activity übergeben Android & Cross-Platform Mobile Apps 0
M Fehler ohne Sinn? java.lang.RuntimeException: Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 11
S Android Eclipse erstellt keine main Activity Android & Cross-Platform Mobile Apps 4
B java.lang.RuntimeException: Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 2
K Android Activity for result aus Dialog Android & Cross-Platform Mobile Apps 1
S Android "Weiches wechseln" zwischen Views in einer Activity Android & Cross-Platform Mobile Apps 3
D Android Activity mit mehreren Views "spliten" Android & Cross-Platform Mobile Apps 10
G Activity-Wechsel bitte ohne Notification Android & Cross-Platform Mobile Apps 6
G eine Methode einer anderen Activity aufrufen Android & Cross-Platform Mobile Apps 9
S Android In Service überprüfen ob eine Activity gebunden ist? Android & Cross-Platform Mobile Apps 6
T Android Activity finished testen Android & Cross-Platform Mobile Apps 5
T Activity / Application fundamentals Android & Cross-Platform Mobile Apps 4
M Activity wechseln aus List View mit Android & Cross-Platform Mobile Apps 2
G extends Activity für Berechnungen? Android & Cross-Platform Mobile Apps 7
G Daten von einer Activity zur nächsten übergeben Android & Cross-Platform Mobile Apps 6
G selbes Menü auf jeder Activity Android & Cross-Platform Mobile Apps 4
C Activity ohne Aktion starten Android & Cross-Platform Mobile Apps 8
C Android Kommunikation zwischen Service und Activity Android & Cross-Platform Mobile Apps 8
Maxim6394 [ Android ] Activity ändern Android & Cross-Platform Mobile Apps 9
A Activity Intent 'source not found' Android & Cross-Platform Mobile Apps 4
A Android Activity Variablen-Initialisierung Android & Cross-Platform Mobile Apps 8
A Beenden einer 2ten Activity Android & Cross-Platform Mobile Apps 3
W Standard Gallery Activity? Android & Cross-Platform Mobile Apps 22
schlingel Android: Overlay in Activity Android & Cross-Platform Mobile Apps 3
G Activity beenden Android & Cross-Platform Mobile Apps 2
N Android Änderung von tabwidget height lässt text verschwinden Android & Cross-Platform Mobile Apps 3

Ähnliche Java Themen

Neue Themen


Oben