Mr. Idle
- Forum-Beiträge: 3
14.10.2013, 21:59:19 via Website
14.10.2013 21:59:19 via Website
Hallo erstmal .
Ich bin neu hier und habe heute den 3. Anlauf gestartet eine meiner iOS-Apps auf Android zu portieren.
Leider bin ich nicht sehr weit gekommen .
Ich möchte mich im vorraus schonmal dafür entschuldigen falls ich unverständliches Zeug schreibe oder mich umständlich ausdrücke.
Ich hab die Zusammenhänge und Begrifflichkeiten von Android noch nicht drauf aber ich hoffe, man kann mich verstehen .
Ich versuche eine ähnliche Navigation wie in diesem Tutorial erklärt zu bauen:
(sry, ich darf wohl noch keine richtigen Links posten, spielt aber eigentlich auch keine Rolle ^^)
Das klappt soweit auch ganz gut, nur jetzt möchte ich die einzelnen Tabs nicht direkt durch die Layouts initialisieren, sondern durch eine Activity.
Klicke ich allerdings auf einen Tab, welcher durch eine Activity initialisiert wird, crasht die App und ich habe keine Ahnung warum.
Hier mal mein Code:
MainActivity:
activity_main.xml:
SettingsActivity:
Fehlermeldung:
[Android Application]
DalvikVM[localhost:8640]
Thread [<1> main] (Suspended (exception IllegalStateException))
<VM does not provide monitor information>
TabHost.setCurrentTab(int) line: 413
TabHost$2.onTabSelectionChanged(int, boolean) line: 154
TabWidget$TabClickListener.onClick(View) line: 546
LinearLayout(View).performClick() line: 4240
View$PerformClick.run() line: 17721
Handler.handleCallback(Message) line: 730
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 137
ActivityThread.main(String[]) line: 5103
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 525
ZygoteInit$MethodAndArgsCaller.run() line: 737
ZygoteInit.main(String[]) line: 553
Thread [<10> Binder_2] (Running)
Thread [<9> Binder_1] (Running)
Sorry für diese wall of text aber vielleicht kann mir ja jemand helfen... ich hoffe es .
Ich bin neu hier und habe heute den 3. Anlauf gestartet eine meiner iOS-Apps auf Android zu portieren.
Leider bin ich nicht sehr weit gekommen .
Ich möchte mich im vorraus schonmal dafür entschuldigen falls ich unverständliches Zeug schreibe oder mich umständlich ausdrücke.
Ich hab die Zusammenhänge und Begrifflichkeiten von Android noch nicht drauf aber ich hoffe, man kann mich verstehen .
Ich versuche eine ähnliche Navigation wie in diesem Tutorial erklärt zu bauen:
(sry, ich darf wohl noch keine richtigen Links posten, spielt aber eigentlich auch keine Rolle ^^)
Das klappt soweit auch ganz gut, nur jetzt möchte ich die einzelnen Tabs nicht direkt durch die Layouts initialisieren, sondern durch eine Activity.
Klicke ich allerdings auf einen Tab, welcher durch eine Activity initialisiert wird, crasht die App und ich habe keine Ahnung warum.
Hier mal mein Code:
MainActivity:
1package xxx;
2
3import android.os.Bundle;
4import android.app.Activity;
5import android.content.Intent;
6import android.view.Menu;
7import android.widget.TabHost;
8import android.widget.TabHost.OnTabChangeListener;
9
10public class MainActivity extends Activity implements OnTabChangeListener
11{
12
13 @Override
14 protected void onCreate(Bundle savedInstanceState)
15 {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.activity_main);
18 initTabs();
19 }
20
21 @Override
22 public boolean onCreateOptionsMenu(Menu menu)
23 {
24 // Inflate the menu; this adds items to the action bar if it is present.
25 getMenuInflater().inflate(R.menu.main, menu);
26 return true;
27 }
28
29
30 private void initTabs()
31 {
32 TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
33 tabHost.setup();
34
35
36 tabHost.addTab(tabHost.newTabSpec("Übersicht").setIndicator("Übersicht").setContent(R.id.tab1)); // <- geht
37 tabHost.addTab(tabHost.newTabSpec("Einstellungen").setIndicator("Einstellungen").setContent(new Intent(this, SettingsActivity.class))); <- crash
38
39 tabHost.setOnTabChangedListener(this);
40
41 tabHost.setCurrentTab(0);
42 }
43
44
45 @Override
46 public void onTabChanged(String tabId)
47 {
48 // TODO Auto-generated method stub
49 }
50}
2
3import android.os.Bundle;
4import android.app.Activity;
5import android.content.Intent;
6import android.view.Menu;
7import android.widget.TabHost;
8import android.widget.TabHost.OnTabChangeListener;
9
10public class MainActivity extends Activity implements OnTabChangeListener
11{
12
13 @Override
14 protected void onCreate(Bundle savedInstanceState)
15 {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.activity_main);
18 initTabs();
19 }
20
21 @Override
22 public boolean onCreateOptionsMenu(Menu menu)
23 {
24 // Inflate the menu; this adds items to the action bar if it is present.
25 getMenuInflater().inflate(R.menu.main, menu);
26 return true;
27 }
28
29
30 private void initTabs()
31 {
32 TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
33 tabHost.setup();
34
35
36 tabHost.addTab(tabHost.newTabSpec("Übersicht").setIndicator("Übersicht").setContent(R.id.tab1)); // <- geht
37 tabHost.addTab(tabHost.newTabSpec("Einstellungen").setIndicator("Einstellungen").setContent(new Intent(this, SettingsActivity.class))); <- crash
38
39 tabHost.setOnTabChangedListener(this);
40
41 tabHost.setCurrentTab(0);
42 }
43
44
45 @Override
46 public void onTabChanged(String tabId)
47 {
48 // TODO Auto-generated method stub
49 }
50}
activity_main.xml:
1<RelativeLayout xmlns:android=
2 xmlns:tools=""
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:paddingBottom="@dimen/activity_vertical_margin"
6 android:paddingLeft="@dimen/activity_horizontal_margin"
7 android:paddingRight="@dimen/activity_horizontal_margin"
8 android:paddingTop="@dimen/activity_vertical_margin"
9 tools:context=".MainActivity" >
10
11 <TabHost
12 android:id="@android:id/tabhost"
13 android:layout_width="match_parent"
14 android:layout_height="match_parent"
15 android:layout_alignParentBottom="true"
16 android:layout_alignParentLeft="true"
17 android:layout_alignParentRight="true"
18 android:layout_alignParentTop="true" >
19
20 <LinearLayout
21 android:layout_width="match_parent"
22 android:layout_height="match_parent"
23 android:orientation="vertical" >
24
25 <TabWidget
26 android:id="@android:id/tabs"
27 android:layout_width="match_parent"
28 android:layout_height="wrap_content" >
29 </TabWidget>
30
31 <FrameLayout
32 android:id="@android:id/tabcontent"
33 android:layout_width="match_parent"
34 android:layout_height="match_parent" >
35
36 <LinearLayout
37 android:id="@+id/tab1"
38 android:layout_width="match_parent"
39 android:layout_height="match_parent"
40 android:orientation="horizontal" >
41
42 </LinearLayout>
43
44 <LinearLayout
45 android:id="@+id/tab2"
46 android:layout_width="match_parent"
47 android:layout_height="match_parent"
48 android:orientation="horizontal" >
49
50 </LinearLayout>
51
52 <LinearLayout
53 android:id="@+id/tab3"
54 android:layout_width="match_parent"
55 android:layout_height="match_parent"
56 android:orientation="horizontal" >
57
58 </LinearLayout>
59
60 <LinearLayout
61 android:id="@+id/tab4"
62 android:layout_width="match_parent"
63 android:layout_height="match_parent"
64 android:orientation="horizontal" >
65
66 </LinearLayout>
67 </FrameLayout>
68 </LinearLayout>
69 </TabHost>
70</RelativeLayout>
2 xmlns:tools=""
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:paddingBottom="@dimen/activity_vertical_margin"
6 android:paddingLeft="@dimen/activity_horizontal_margin"
7 android:paddingRight="@dimen/activity_horizontal_margin"
8 android:paddingTop="@dimen/activity_vertical_margin"
9 tools:context=".MainActivity" >
10
11 <TabHost
12 android:id="@android:id/tabhost"
13 android:layout_width="match_parent"
14 android:layout_height="match_parent"
15 android:layout_alignParentBottom="true"
16 android:layout_alignParentLeft="true"
17 android:layout_alignParentRight="true"
18 android:layout_alignParentTop="true" >
19
20 <LinearLayout
21 android:layout_width="match_parent"
22 android:layout_height="match_parent"
23 android:orientation="vertical" >
24
25 <TabWidget
26 android:id="@android:id/tabs"
27 android:layout_width="match_parent"
28 android:layout_height="wrap_content" >
29 </TabWidget>
30
31 <FrameLayout
32 android:id="@android:id/tabcontent"
33 android:layout_width="match_parent"
34 android:layout_height="match_parent" >
35
36 <LinearLayout
37 android:id="@+id/tab1"
38 android:layout_width="match_parent"
39 android:layout_height="match_parent"
40 android:orientation="horizontal" >
41
42 </LinearLayout>
43
44 <LinearLayout
45 android:id="@+id/tab2"
46 android:layout_width="match_parent"
47 android:layout_height="match_parent"
48 android:orientation="horizontal" >
49
50 </LinearLayout>
51
52 <LinearLayout
53 android:id="@+id/tab3"
54 android:layout_width="match_parent"
55 android:layout_height="match_parent"
56 android:orientation="horizontal" >
57
58 </LinearLayout>
59
60 <LinearLayout
61 android:id="@+id/tab4"
62 android:layout_width="match_parent"
63 android:layout_height="match_parent"
64 android:orientation="horizontal" >
65
66 </LinearLayout>
67 </FrameLayout>
68 </LinearLayout>
69 </TabHost>
70</RelativeLayout>
SettingsActivity:
1package xxx;
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.widget.TextView;
6
7public class SettingsActivity extends Activity
8{
9 @Override
10 public void onCreate(Bundle savedInstanceState)
11 {
12 super.onCreate(savedInstanceState);
13
14 TextView tv = new TextView(this);
15 tv.setText("This is tab 2");
16 setContentView(tv);
17 }
18}
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.widget.TextView;
6
7public class SettingsActivity extends Activity
8{
9 @Override
10 public void onCreate(Bundle savedInstanceState)
11 {
12 super.onCreate(savedInstanceState);
13
14 TextView tv = new TextView(this);
15 tv.setText("This is tab 2");
16 setContentView(tv);
17 }
18}
Fehlermeldung:
[Android Application]
DalvikVM[localhost:8640]
Thread [<1> main] (Suspended (exception IllegalStateException))
<VM does not provide monitor information>
TabHost.setCurrentTab(int) line: 413
TabHost$2.onTabSelectionChanged(int, boolean) line: 154
TabWidget$TabClickListener.onClick(View) line: 546
LinearLayout(View).performClick() line: 4240
View$PerformClick.run() line: 17721
Handler.handleCallback(Message) line: 730
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 137
ActivityThread.main(String[]) line: 5103
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 525
ZygoteInit$MethodAndArgsCaller.run() line: 737
ZygoteInit.main(String[]) line: 553
Thread [<10> Binder_2] (Running)
Thread [<9> Binder_1] (Running)
Sorry für diese wall of text aber vielleicht kann mir ja jemand helfen... ich hoffe es .
— geändert am 14.10.2013, 22:00:12