Android tabs ohne xml

StrikeTom

Bekanntes Mitglied
Hallo Leute,
ich habe folgenden Code:
Java:
public class MyActivity  extends TabActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final TabHost tabHost = getTabHost();
        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("tab1")
                .setContent(this));
        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("tab2")
                .setContent(this));
    }
}
Wie fülle ich die Tabs jetzt mit inhalt?:rtfm::noe:
Brauche ich dafür jeweils eine Activity?
Ich möchte gerne ohne xml machen, weil ich das vom Stil schöner finde:D

Danke im vorraus;)
 
T

Tomate_Salat

Gast
Ich würde mal mindestens setContentView(...); noch enstprechend aufrufen. Aber was du genau machen willst, ist mir nicht so klar.

Ich finde die Xmls schöner. Vor allem weil du sehr viel sehr elegant darüber konfigurieren kannst.
 

StrikeTom

Bekanntes Mitglied
Hab ich auch schon gemacht, hilft mir nicht weiter!
Java:
public class MyActivity  extends TabActivity{
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        final TabHost tabHost = getTabHost();
        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("tab1")
                .setContent(this));
        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("tab2")
                .setContent(this));
    }
}

    /** {@inheritDoc} */
    public View createTabContent(String tag) {
    	if(tag.equals("tab1")){
    	TextView tv = new TextView(this);
            tv.setText("tab1");
            return tv;
    	}
    	if(tag.equals("tab2")){
    	TextView tv = new TextView(this);
            tv.setText("tab2");
            return tv;
    	}
        return null;
    }
}

Danke für die schnelle Antwort :)!
Mit xml komme ich mit tabs nicht so gut klar:bahnhof:
 
T

Tomate_Salat

Gast
Bin selber recht neu ein Android. Aber schau mal hier. Scheint wohl so ähnlich eh zu laufen, wie du es schon hast. Anscheinend sind die einzelnen Tabs einfach einzelne Activities die du dann zuweist. (habs nur grob überflogen).
 

StrikeTom

Bekanntes Mitglied
Danke, ich habe die Seite schon gesehen, aber das Funktioniert bei mir
nicht. Kann es daran liegen, dass ich keine Icons benutze?
 
T

Tomate_Salat

Gast
Wäre z.B. afaik bei Notifications ein Grund. Von daher will ichs mal nicht ausschließen. Ich werde das Beispiel selber mal testen (mit+ohne icons).

Edit:
You need an icon for each of your tabs

aber du hast ja ein haufen zur verfügung. Z.b. unter: [c]@android:drawables/...[/c]

Edit2:
Mit Icons funktioniert es bei mir einwandfrei.
 
Zuletzt bearbeitet von einem Moderator:
Ähnliche Java Themen
  Titel Forum Antworten Datum
N Android Informationen zwischen Tabs austauschen Android & Cross-Platform Mobile Apps 2
D Android Tabs nutzen - PagerTitleStrip haut nicht hin Android & Cross-Platform Mobile Apps 4
L Android ActionBar mit unterschiedlichen Farben für Tabs Android & Cross-Platform Mobile Apps 3
N Android Retain-Fragment + ActionBar-Tabs = Absturz!? Android & Cross-Platform Mobile Apps 9
D TabHost mit Tabs verschieben und Bilder einsetzen Android & Cross-Platform Mobile Apps 7
Naxon89 Duplicate class kotlin - und dies ohne das es angewendet wird Android & Cross-Platform Mobile Apps 1
I Android ListView, Werte aktualisieren ohne die Liste komplett neu zu laden Android & Cross-Platform Mobile Apps 5
T Screenshot speichern ohne alte Datei überschreiben Android & Cross-Platform Mobile Apps 3
T Android ArrayList sortieren mit 2 Werten ohne thencomparing , Wie? Android & Cross-Platform Mobile Apps 10
Jackii Android Android Studio Error im Testlauf ohne zu programmieren Android & Cross-Platform Mobile Apps 9
L Android App ohne MainActivity Android & Cross-Platform Mobile Apps 3
J Android LogIn/Registrierung ohne Mail-Adresse Android & Cross-Platform Mobile Apps 1
B Android USB Debugging ohne kabel möglich? Android & Cross-Platform Mobile Apps 5
G Accelerometer ohne Activity Android & Cross-Platform Mobile Apps 8
M Fehler ohne Sinn? java.lang.RuntimeException: Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 11
G Activity-Wechsel bitte ohne Notification Android & Cross-Platform Mobile Apps 6
G Pause ohne sleep und ohne zweiten Thread Android & Cross-Platform Mobile Apps 5
G Pause im Programmablauf ohne extra Thread Android & Cross-Platform Mobile Apps 2
C Activity ohne Aktion starten Android & Cross-Platform Mobile Apps 8
S Entwicklung von Smartphone programmen ohne selber eins zu besitzen Android & Cross-Platform Mobile Apps 17

Ähnliche Java Themen

Neue Themen


Oben