- Forum-Beiträge: 23
08.09.2014, 17:14:29 via Website
08.09.2014 17:14:29 via Website
Aloha Community,
ich versuche für eine App Tabbing zu realisieren.
das ganze soll funktionieren wie folgt:
Ich habe eine bestehende App. Dessen MainActivity soll in Tab1 dargestellt werden und wie bisher funktionieren, wobei alle neuen Activities in dem Tab dargestellt werden.
Ich möchte nun die Möglichkeit haben, einen neuen Tab zu öffnen, in welcher wieder die originale MainActivity geöffnet wird. Hier soll sich die Activity nun auch wieder in dem Tab so verhalten, als gäbe es keinen Tab.
Ich hoffe, ihr versteht, was ich meine.
Bisher bin ich noch nicht weit gekommen:
Ich habe eine DemoApp gefunden, welche mir dynamisch neue Tabs erzeugt und ein wenig editiert.
Was mir fehlt:
*TabAdd-Button soll neben der ActionBar liegen
*Tabs müssen zu schließen sein (bestenfalls mit einem Button im Tab)
*Im Tab soll die ehemalige MainActivity laufen.
meine bisherige MainActivity:
<code>
package com.example.app.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AnalogClock;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
public class MainActivity extends Activity {
private int counter = 0;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
final TabHost tabs=(TabHost)findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("buttontab");
spec.setContent(R.id.buttontab);
spec.setIndicator("Button");
tabs.addTab(spec);
Button btn=(Button)tabs.getCurrentView().findViewById(R.id.buttontab);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(final View view) {
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
//instead of AnalogClock run the TabActivity
return (new AnalogClock(MainActivity.this));
// ???? but TabActivity is a activity not a view...
//return (new MainActivity(MainActivity.this));
}
});
incCounter();
int counter = getCounter();
spec.setIndicator("Tab "+counter); //$NON-NLS-1$
tabs.addTab(spec);
}
});
}
public void newTab (View view) {
Intent intent = new Intent(this, TabActivity.class);
startActivity(intent);
}
public void incCounter(){
this.counter++;
}
public int getCounter(){
return this.counter;
}
public void decCounter(){
this.counter--;
}
}
</code>
das Layout:
<code>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="62px">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/buttontab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/buttonrmtab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
</TableLayout>
</FrameLayout>
</TabHost>
</LinearLayout>
</code>
Kann mir jemand ein gutes Tutorial dazu geben, oder mir anderweitig unter die Arme greifen? Ich hänge da seit einigen Tagen dran, bin aber außer Abstürzen und Frustration noch zu nicht viel gekommen.
Grüße!
— geändert am 09.09.2014, 14:56:39
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.