Maria Kugler
- Forum-Beiträge: 3
19.02.2011, 16:47:07 via Website
19.02.2011 16:47:07 via Website
Hallo liebe Android-Entwickler,
ich muss derzeit für die Uni eine Android-App programmieren.
Mein Problem hier ist das folgende:
meine Activity ist layouttechnisch in einen oberen und einen unteren Teil aufgeteilt.
Im oberen Teil befindet sich links ein Bild (ImageView) und rechts Name und Status-Nachricht (jeweils TextView).
Im unteren Teil ist ein TabHost mit 3 Tabs.
Anzeigetechnisch funktioniert auch alles.
Nun möchte ich in meiner *.java auf die TextViews im oberen Teil zugreifen um dort den Stil, aber natürlich auch den Inhalt verändern zu können.
Das geht aber irgendwie einfach nicht und die App wir "geforceclosed" sobald ich in der App auf den Button klicke, der zu dieser *.java verweist.
Es wäre nett, wenn mir jemand verraten kann, wie ich in meiner *.java (mit "extends TabActivity") auf die TextViews zugreifen kann, die layouttechnisch eben NICHT im TabHost angesiedelt sind.
Meine Class:
und hier das Layout:
Vielen Dank auf jeden Fall schonmal im Voraus. Ich hoffe, irgendjemand kann mir da helfen.
Viele Grüße
Maria
ich muss derzeit für die Uni eine Android-App programmieren.
Mein Problem hier ist das folgende:
meine Activity ist layouttechnisch in einen oberen und einen unteren Teil aufgeteilt.
Im oberen Teil befindet sich links ein Bild (ImageView) und rechts Name und Status-Nachricht (jeweils TextView).
Im unteren Teil ist ein TabHost mit 3 Tabs.
Anzeigetechnisch funktioniert auch alles.
Nun möchte ich in meiner *.java auf die TextViews im oberen Teil zugreifen um dort den Stil, aber natürlich auch den Inhalt verändern zu können.
Das geht aber irgendwie einfach nicht und die App wir "geforceclosed" sobald ich in der App auf den Button klicke, der zu dieser *.java verweist.
Es wäre nett, wenn mir jemand verraten kann, wie ich in meiner *.java (mit "extends TabActivity") auf die TextViews zugreifen kann, die layouttechnisch eben NICHT im TabHost angesiedelt sind.
Meine Class:
1import android.app.TabActivity;
2import android.content.Intent;
3import android.graphics.Typeface;
4import android.os.Bundle;
5import android.widget.TabHost;
6import android.widget.TextView;
7
8
9public class Profile extends TabActivity
10{
11 private TextView Profile_State;
12
13 @Override
14 public void onCreate(Bundle icicle)
15 {
16 super.onCreate(icicle);
17 setContentView(R.layout.profile);
18
19 Profile_State = (TextView)findViewById(R.id.profile_state);
20
21 Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Sansation.ttf");
22
23 Profile_State.setTypeface(face);
24
25
26 Profile_State.setText("I'm currently programming an Android App ");
27
28 TabHost tabHost = getTabHost();
29 TabHost.TabSpec spec;
30 Intent intent;
31
32 intent = new Intent().setClass(this, Wall.class);
33 spec = tabHost.newTabSpec("wall").setIndicator("Wall")
34 .setContent(intent);
35 tabHost.addTab(spec);
36
37
38 intent = new Intent().setClass(this, Info.class);
39 spec = tabHost.newTabSpec("info").setIndicator("Info")
40 .setContent(intent);
41 tabHost.addTab(spec);
42
43
44 intent = new Intent().setClass(this, Car.class);
45 spec = tabHost.newTabSpec("car").setIndicator("Car")
46 .setContent(intent);
47 tabHost.addTab(spec);
48
49 tabHost.setCurrentTab(0);
50 }
51
52}
2import android.content.Intent;
3import android.graphics.Typeface;
4import android.os.Bundle;
5import android.widget.TabHost;
6import android.widget.TextView;
7
8
9public class Profile extends TabActivity
10{
11 private TextView Profile_State;
12
13 @Override
14 public void onCreate(Bundle icicle)
15 {
16 super.onCreate(icicle);
17 setContentView(R.layout.profile);
18
19 Profile_State = (TextView)findViewById(R.id.profile_state);
20
21 Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Sansation.ttf");
22
23 Profile_State.setTypeface(face);
24
25
26 Profile_State.setText("I'm currently programming an Android App ");
27
28 TabHost tabHost = getTabHost();
29 TabHost.TabSpec spec;
30 Intent intent;
31
32 intent = new Intent().setClass(this, Wall.class);
33 spec = tabHost.newTabSpec("wall").setIndicator("Wall")
34 .setContent(intent);
35 tabHost.addTab(spec);
36
37
38 intent = new Intent().setClass(this, Info.class);
39 spec = tabHost.newTabSpec("info").setIndicator("Info")
40 .setContent(intent);
41 tabHost.addTab(spec);
42
43
44 intent = new Intent().setClass(this, Car.class);
45 spec = tabHost.newTabSpec("car").setIndicator("Car")
46 .setContent(intent);
47 tabHost.addTab(spec);
48
49 tabHost.setCurrentTab(0);
50 }
51
52}
und hier das Layout:
1<?xml version="1.0" encoding="utf-8"?>
2
3<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4 android:orientation="vertical"
5 android:layout_width="fill_parent"
6 android:layout_height="fill_parent"
7 android:background="@drawable/profile_background">
8
9 <LinearLayout android:id="@+id/profile_info"
10 android:layout_width="fill_parent"
11 android:layout_height="wrap_content"
12 android:layout_above="@+id/Profile_Tabs"
13 android:layout_alignParentLeft="true"
14 android:layout_alignParentTop="true"
15 android:orientation="horizontal">
16
17 <!-- Profile Pics im Seitenverhältnis 3:4 -->
18 <ImageButton android:id="@+id/profile_pic"
19 android:layout_width="180dp"
20 android:layout_height="240dp"
21 android:onClick="OnClickPic"
22 android:background="@drawable/profile_pic"
23 android:layout_marginLeft="13dp"
24 android:layout_marginTop="52dp"/>
25
26 <LinearLayout android:id="@+id/profile_state"
27 android:orientation="vertical"
28 android:layout_width="200dp"
29 android:layout_height="wrap_content"
30 android:layout_alignParentRight="true"
31 android:layout_alignParentTop="true">
32
33 <TextView android:id="@+id/profile_prename"
34 android:textSize="30dp"
35 android:textColor="#ffcccccc"
36 android:maxLines="1"
37 android:layout_height="wrap_content"
38 android:layout_marginTop="52dp"
39 android:layout_marginRight="7dp"
40 android:layout_marginLeft="13dp"
41 android:layout_width="180dp"
42 android:text="nachname">
43 </TextView>
44
45 <TextView android:id="@+id/profile_surname"
46 android:textSize="30dp"
47 android:textColor="#ffffffff"
48 android:maxLines="1"
49 android:layout_height="wrap_content"
50 android:layout_marginRight="7dp"
51 android:layout_marginLeft="13dp"
52 android:layout_width="180dp"
53 android:text="vorname">
54
55 </TextView>
56
57 <TextView android:id="@+id/profile_state"
58 android:textSize="20dp"
59 android:textColor="#ffffffff"
60 android:maxLines="3"
61 android:layout_height="120dp"
62 android:layout_marginTop="50dp"
63 android:layout_marginRight="10dp"
64 android:layout_marginLeft="18dp"
65 android:layout_width="172dp" />
66
67
68 </LinearLayout>
69
70
71 </LinearLayout>
72
73 <LinearLayout android:id="@+id/profile_tabhost"
74 android:layout_width="fill_parent"
75 android:layout_height="450dp"
76 android:layout_alignParentRight="true"
77 android:layout_alignParentBottom="true">
78
79 <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
80 android:id="@android:id/tabhost"
81 android:layout_width="fill_parent"
82 android:layout_height="wrap_content">
83
84 <LinearLayout
85 android:orientation="vertical"
86 android:layout_width="fill_parent"
87 android:layout_height="fill_parent"
88 android:layout_marginBottom="0dp">
89
90 <TabWidget
91 android:id="@android:id/tabs"
92 android:layout_width="fill_parent"
93 android:layout_height="40dp" />
94 <FrameLayout
95 android:id="@android:id/tabcontent"
96 android:layout_width="fill_parent"
97 android:layout_height="410dp"/>
98 </LinearLayout>
99 </TabHost>
100 </LinearLayout>
101
102
103</LinearLayout>
2
3<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4 android:orientation="vertical"
5 android:layout_width="fill_parent"
6 android:layout_height="fill_parent"
7 android:background="@drawable/profile_background">
8
9 <LinearLayout android:id="@+id/profile_info"
10 android:layout_width="fill_parent"
11 android:layout_height="wrap_content"
12 android:layout_above="@+id/Profile_Tabs"
13 android:layout_alignParentLeft="true"
14 android:layout_alignParentTop="true"
15 android:orientation="horizontal">
16
17 <!-- Profile Pics im Seitenverhältnis 3:4 -->
18 <ImageButton android:id="@+id/profile_pic"
19 android:layout_width="180dp"
20 android:layout_height="240dp"
21 android:onClick="OnClickPic"
22 android:background="@drawable/profile_pic"
23 android:layout_marginLeft="13dp"
24 android:layout_marginTop="52dp"/>
25
26 <LinearLayout android:id="@+id/profile_state"
27 android:orientation="vertical"
28 android:layout_width="200dp"
29 android:layout_height="wrap_content"
30 android:layout_alignParentRight="true"
31 android:layout_alignParentTop="true">
32
33 <TextView android:id="@+id/profile_prename"
34 android:textSize="30dp"
35 android:textColor="#ffcccccc"
36 android:maxLines="1"
37 android:layout_height="wrap_content"
38 android:layout_marginTop="52dp"
39 android:layout_marginRight="7dp"
40 android:layout_marginLeft="13dp"
41 android:layout_width="180dp"
42 android:text="nachname">
43 </TextView>
44
45 <TextView android:id="@+id/profile_surname"
46 android:textSize="30dp"
47 android:textColor="#ffffffff"
48 android:maxLines="1"
49 android:layout_height="wrap_content"
50 android:layout_marginRight="7dp"
51 android:layout_marginLeft="13dp"
52 android:layout_width="180dp"
53 android:text="vorname">
54
55 </TextView>
56
57 <TextView android:id="@+id/profile_state"
58 android:textSize="20dp"
59 android:textColor="#ffffffff"
60 android:maxLines="3"
61 android:layout_height="120dp"
62 android:layout_marginTop="50dp"
63 android:layout_marginRight="10dp"
64 android:layout_marginLeft="18dp"
65 android:layout_width="172dp" />
66
67
68 </LinearLayout>
69
70
71 </LinearLayout>
72
73 <LinearLayout android:id="@+id/profile_tabhost"
74 android:layout_width="fill_parent"
75 android:layout_height="450dp"
76 android:layout_alignParentRight="true"
77 android:layout_alignParentBottom="true">
78
79 <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
80 android:id="@android:id/tabhost"
81 android:layout_width="fill_parent"
82 android:layout_height="wrap_content">
83
84 <LinearLayout
85 android:orientation="vertical"
86 android:layout_width="fill_parent"
87 android:layout_height="fill_parent"
88 android:layout_marginBottom="0dp">
89
90 <TabWidget
91 android:id="@android:id/tabs"
92 android:layout_width="fill_parent"
93 android:layout_height="40dp" />
94 <FrameLayout
95 android:id="@android:id/tabcontent"
96 android:layout_width="fill_parent"
97 android:layout_height="410dp"/>
98 </LinearLayout>
99 </TabHost>
100 </LinearLayout>
101
102
103</LinearLayout>
Vielen Dank auf jeden Fall schonmal im Voraus. Ich hoffe, irgendjemand kann mir da helfen.
Viele Grüße
Maria
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.