Ben Becker
- Forum-Beiträge: 209
06.06.2011, 22:37:08 via Website
06.06.2011 22:37:08 via Website
Hiho!
ich kommt mit einem TabHostLayout nicht weiter. Leider weiß ich auch gar nicht ob das geht wie ich das will. Und zwar würde ich gerne 3 Tabs haben. Auf den ersten beiden Soll eine Tabelle sein die Scrollbar ist und aus einer Datenbank befüllt wird. Auf der dritten ist eine Tabelle mit zwei Zeilen und darunter noch Infos. Geht sowas?
Ich habe mir gedacht, ich mache das TabHostLayout so:
Ja an die Stelle wo steht "HIER DANN DIE TABELLEN REIN" würde ich gerne die Tabellen einbinden und die Infos. Kann man das Dynamisch machen? Also über die Activity? Will nicht ewig suchen und dabei geht sowas nicht.
Ich habe das natürlich auch schon mal versucht. Einfach in dem ich versuche eine Textview zu ersetzen. Aber das Programm stürzt ab und startet erst gar nicht. Hier mal die class Datei die die textview ändern soll, dann die Tabhost Datei und das Layout:
Warum stürzt mein Programm ab und geht das überhaupt was ich machen will?
ich kommt mit einem TabHostLayout nicht weiter. Leider weiß ich auch gar nicht ob das geht wie ich das will. Und zwar würde ich gerne 3 Tabs haben. Auf den ersten beiden Soll eine Tabelle sein die Scrollbar ist und aus einer Datenbank befüllt wird. Auf der dritten ist eine Tabelle mit zwei Zeilen und darunter noch Infos. Geht sowas?
Ich habe mir gedacht, ich mache das TabHostLayout so:
1<?xml version="1.0" encoding="utf-8"?>
2<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@android:id/tabhost"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent">
6 <RelativeLayout
7 android:orientation="vertical"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 android:id="@+id/rl1">
11 <LinearLayout
12 android:orientation="vertical"
13 android:layout_width="fill_parent"
14 android:layout_height="fill_parent"
15 android:id="@+id/ll1">
16 HIER DANN DIE TABELLEN REIN
17 </LinearLayout>
18 <TabWidget
19 android:id="@android:id/tabs"
20 android:layout_width="fill_parent"
21 android:layout_height="wrap_content"
22 android:layout_alignParentBottom="true"/>
23 <FrameLayout
24 android:id="@android:id/tabcontent"
25 android:layout_width="fill_parent"
26 android:layout_height="fill_parent"
27 android:padding="5dp" >
28 </FrameLayout>
29 </RelativeLayout>
30</TabHost>
2<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@android:id/tabhost"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent">
6 <RelativeLayout
7 android:orientation="vertical"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 android:id="@+id/rl1">
11 <LinearLayout
12 android:orientation="vertical"
13 android:layout_width="fill_parent"
14 android:layout_height="fill_parent"
15 android:id="@+id/ll1">
16 HIER DANN DIE TABELLEN REIN
17 </LinearLayout>
18 <TabWidget
19 android:id="@android:id/tabs"
20 android:layout_width="fill_parent"
21 android:layout_height="wrap_content"
22 android:layout_alignParentBottom="true"/>
23 <FrameLayout
24 android:id="@android:id/tabcontent"
25 android:layout_width="fill_parent"
26 android:layout_height="fill_parent"
27 android:padding="5dp" >
28 </FrameLayout>
29 </RelativeLayout>
30</TabHost>
Ja an die Stelle wo steht "HIER DANN DIE TABELLEN REIN" würde ich gerne die Tabellen einbinden und die Infos. Kann man das Dynamisch machen? Also über die Activity? Will nicht ewig suchen und dabei geht sowas nicht.
Ich habe das natürlich auch schon mal versucht. Einfach in dem ich versuche eine Textview zu ersetzen. Aber das Programm stürzt ab und startet erst gar nicht. Hier mal die class Datei die die textview ändern soll, dann die Tabhost Datei und das Layout:
1package de.sportwettenblogger.de.tabwidget;
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.widget.TextView;
6
7public class ArtistsActivity extends Activity {
8
9 public void onCreate(Bundle savedInstanceState) {
10 super.onCreate(savedInstanceState);
11
12 TextView textview = new TextView(this);
13 textview =(TextView) findViewById(R.id.textView1);
14 textview.setText("This is the Artists tab");
15 //setContentView(textview);
16 }
17 }
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.widget.TextView;
6
7public class ArtistsActivity extends Activity {
8
9 public void onCreate(Bundle savedInstanceState) {
10 super.onCreate(savedInstanceState);
11
12 TextView textview = new TextView(this);
13 textview =(TextView) findViewById(R.id.textView1);
14 textview.setText("This is the Artists tab");
15 //setContentView(textview);
16 }
17 }
1package de.sportwettenblogger.de.tabwidget;
2
3import android.app.TabActivity;
4import android.content.Intent;
5import android.content.res.Resources;
6import android.os.Bundle;
7import android.widget.TabHost;
8
9public class TabWidget extends TabActivity {
10 /** Called when the activity is first created. */
11 @Override
12 public void onCreate(Bundle savedInstanceState) {
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.main);
15
16 Resources res = getResources(); // Resource object to get Drawables
17 TabHost tabHost = getTabHost(); // The activity TabHost
18 TabHost.TabSpec spec; // Resusable TabSpec for each tab
19 Intent intent; // Reusable Intent for each tab
20
21 // Create an Intent to launch an Activity for the tab (to be reused)
22 intent = new Intent().setClass(this, ArtistsActivity.class);
23
24 // Initialize a TabSpec for each tab and add it to the TabHost
25 spec = tabHost.newTabSpec("artists").setIndicator("Artists",
26 res.getDrawable(R.drawable.ic_tab_artists))
27 .setContent(intent);
28 tabHost.addTab(spec);
29
30 // Do the same for the other tabs
31 intent = new Intent().setClass(this, AlbumsActivity.class);
32 spec = tabHost.newTabSpec("albums").setIndicator("Albums",
33 res.getDrawable(R.drawable.ic_tab_albums))
34 .setContent(intent);
35 tabHost.addTab(spec);
36
37 intent = new Intent().setClass(this, SongsActivity.class);
38 spec = tabHost.newTabSpec("songs").setIndicator("Songs",
39 res.getDrawable(R.drawable.ic_tab_songs))
40 .setContent(intent);
41 tabHost.addTab(spec);
42
43 tabHost.setCurrentTab(1);
44 }
45}
2
3import android.app.TabActivity;
4import android.content.Intent;
5import android.content.res.Resources;
6import android.os.Bundle;
7import android.widget.TabHost;
8
9public class TabWidget extends TabActivity {
10 /** Called when the activity is first created. */
11 @Override
12 public void onCreate(Bundle savedInstanceState) {
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.main);
15
16 Resources res = getResources(); // Resource object to get Drawables
17 TabHost tabHost = getTabHost(); // The activity TabHost
18 TabHost.TabSpec spec; // Resusable TabSpec for each tab
19 Intent intent; // Reusable Intent for each tab
20
21 // Create an Intent to launch an Activity for the tab (to be reused)
22 intent = new Intent().setClass(this, ArtistsActivity.class);
23
24 // Initialize a TabSpec for each tab and add it to the TabHost
25 spec = tabHost.newTabSpec("artists").setIndicator("Artists",
26 res.getDrawable(R.drawable.ic_tab_artists))
27 .setContent(intent);
28 tabHost.addTab(spec);
29
30 // Do the same for the other tabs
31 intent = new Intent().setClass(this, AlbumsActivity.class);
32 spec = tabHost.newTabSpec("albums").setIndicator("Albums",
33 res.getDrawable(R.drawable.ic_tab_albums))
34 .setContent(intent);
35 tabHost.addTab(spec);
36
37 intent = new Intent().setClass(this, SongsActivity.class);
38 spec = tabHost.newTabSpec("songs").setIndicator("Songs",
39 res.getDrawable(R.drawable.ic_tab_songs))
40 .setContent(intent);
41 tabHost.addTab(spec);
42
43 tabHost.setCurrentTab(1);
44 }
45}
1<?xml version="1.0" encoding="utf-8"?>
2<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@android:id/tabhost"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent">
6 <RelativeLayout
7 android:orientation="vertical"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 android:id="@+id/rl1">
11 <LinearLayout
12 android:orientation="vertical"
13 android:layout_width="fill_parent"
14 android:layout_height="fill_parent"
15 android:id="@+id/ll1">
16 <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
17 </LinearLayout>
18 <TabWidget
19 android:id="@android:id/tabs"
20 android:layout_width="fill_parent"
21 android:layout_height="wrap_content"
22 android:layout_alignParentBottom="true"/>
23 <FrameLayout
24 android:id="@android:id/tabcontent"
25 android:layout_width="fill_parent"
26 android:layout_height="fill_parent"
27 android:padding="5dp" >
28 </FrameLayout>
29 </RelativeLayout>
30</TabHost>
2<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@android:id/tabhost"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent">
6 <RelativeLayout
7 android:orientation="vertical"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 android:id="@+id/rl1">
11 <LinearLayout
12 android:orientation="vertical"
13 android:layout_width="fill_parent"
14 android:layout_height="fill_parent"
15 android:id="@+id/ll1">
16 <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
17 </LinearLayout>
18 <TabWidget
19 android:id="@android:id/tabs"
20 android:layout_width="fill_parent"
21 android:layout_height="wrap_content"
22 android:layout_alignParentBottom="true"/>
23 <FrameLayout
24 android:id="@android:id/tabcontent"
25 android:layout_width="fill_parent"
26 android:layout_height="fill_parent"
27 android:padding="5dp" >
28 </FrameLayout>
29 </RelativeLayout>
30</TabHost>
Warum stürzt mein Programm ab und geht das überhaupt was ich machen will?
— geändert am 06.06.2011, 23:20:10
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.