TabActivity in Java programmieren

  • Antworten:4
  • Bentwortet
Aaron B.
  • Forum-Beiträge: 206

20.04.2013, 17:09:17 via App

Hallo, ich versuche, die Bestandteile einer TabActivity (TabHost, Tabs, TabContent) in Java zu definieren.

Aus irgendeinem Grund funktioniert es aber nicht, sondern es kommt der Fehler: Resource ID #0x0.

Mein script:



package de.MusicIsMyLife.appleartvideos;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.widget.TabHost.*;
import android.content.*;
import android.net.*;

public class Home extends TabActivity
{

TabHost th;
LinearLayout ll;
TabWidget tw;
FrameLayout fl;

@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);

layout();
}

private void layout() {
tw = new TabWidget(this);
tw.setId(android.R.id.tabs);

fl = new FrameLayout(this);
fl.setId(android.R.id.tabcontent);

ll = new LinearLayout(this);
ll.setOrientation(ll.VERTICAL);
ll.addView(tw);
ll.addView(fl);

th = new TabHost(this);
th.setId(android.R.id.tabhost);
th.addView(ll);

setContentView(th);

try {
TabSpec tab1 = getTabHost()
.newTabSpec("Home")
.setContent(new Intent().setClass(this, homi.class))
.setIndicator("Home");

getTabHost().addTab(tab1);
} catch(Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}

}









Wie würde es funktionieren?

LG

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

20.04.2013, 19:30:10 via App

Versuche es doch mal mit den Tabs der ActionBar ich finde es damit einfacher.
Hast du den Code aus irgendeinem Turorial
wenn ja poste mal den Link so etwas interessiert mich auch

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Aaron B.
  • Forum-Beiträge: 206

20.04.2013, 20:41:07 via App

Der Code stammt ursprünglich aus dem internet aber ich weiß nicht mehr genau, woher :/ is schon ziemlich lange her :) aber google einfach mal nach TabActivity :)

LG

— geändert am 20.04.2013, 20:41:16

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

20.04.2013, 20:54:08 via App

ok Danke.
Aber leider kann ich dir gerade nicht helfen.

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Aaron B.
  • Forum-Beiträge: 206

21.04.2013, 00:45:52 via App

Trotzdem danke :)

LG

Antworten