Meresez
- Forum-Beiträge: 31
14.06.2011, 09:30:03 via Website
14.06.2011 09:30:03 via Website
Hallo zusammen
Ich versuche derzeitig eine 2. Activity zu starten sobald der Benutzer den zentralen Knopf/Home Button(wie heisst das Teil eigentlich?) nach unten drückt. Nur leider funktioniert das ganze nicht wie gewünscht Solange ich nur die 1. Activity anzeigen lasse(ohne den Code für das öffnen der 2.Activity) funktioniert alles tip top, das Interface wird angezeigt etc. Füge ich nun jedoch den Code ein und starte die App passiert absolut gar nichts. Der Titel der App wird angezeigt, das wars dann aber auch schon. Der Content wird nicht angezeigt und dementsprechend bleibt der Bildschirm schwarz. Desweiteren passiert auch absolut nichts wenn der Knopf/Home Button gedrückt wird. Weiss jmnd wo das Problem liegt?
AndroidLernenActivity.java:
main.xml:
strings.xml:
Activity2.xml:
Activity2.java:
Ich versuche derzeitig eine 2. Activity zu starten sobald der Benutzer den zentralen Knopf/Home Button(wie heisst das Teil eigentlich?) nach unten drückt. Nur leider funktioniert das ganze nicht wie gewünscht Solange ich nur die 1. Activity anzeigen lasse(ohne den Code für das öffnen der 2.Activity) funktioniert alles tip top, das Interface wird angezeigt etc. Füge ich nun jedoch den Code ein und starte die App passiert absolut gar nichts. Der Titel der App wird angezeigt, das wars dann aber auch schon. Der Content wird nicht angezeigt und dementsprechend bleibt der Bildschirm schwarz. Desweiteren passiert auch absolut nichts wenn der Knopf/Home Button gedrückt wird. Weiss jmnd wo das Problem liegt?
AndroidLernenActivity.java:
1package ch.android.com;
2// Seite 47 im englischen PDF
3import android.app.Activity;
4import android.content.Intent;
5import android.os.Bundle;
6import android.view.KeyEvent;
7
8public class AndroidLernenActivity extends Activity {
9 String tag ="Events";
10
11
12 /** Called when the activity is first created. */
13 @Override
14 public void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 //---hides the title bar---
17 //requestWindowFeature(Window.FEATURE_NO_TITLE);
18 setContentView(R.layout.main);
19 // Log.d(tag, "In the onCreate() event");
20 }
21 public boolean onKeyDown(int keyCode, KeyEvent event)
22 {
23 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
24 {
25 startActivity(new Intent ("ch.android.Activity2")) ;
26 }
27 return false;
28 }
29
30 public void onStart() { /*...*/}
31 public void onRestart() { /*...*/}
32 public void onResume() { /*...*/}
33 public void onPause() { /*...*/}
34 public void onStop() { /*...*/}
35 public void onDestroy() { /*...*/}
36}
Manifest:2// Seite 47 im englischen PDF
3import android.app.Activity;
4import android.content.Intent;
5import android.os.Bundle;
6import android.view.KeyEvent;
7
8public class AndroidLernenActivity extends Activity {
9 String tag ="Events";
10
11
12 /** Called when the activity is first created. */
13 @Override
14 public void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 //---hides the title bar---
17 //requestWindowFeature(Window.FEATURE_NO_TITLE);
18 setContentView(R.layout.main);
19 // Log.d(tag, "In the onCreate() event");
20 }
21 public boolean onKeyDown(int keyCode, KeyEvent event)
22 {
23 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
24 {
25 startActivity(new Intent ("ch.android.Activity2")) ;
26 }
27 return false;
28 }
29
30 public void onStart() { /*...*/}
31 public void onRestart() { /*...*/}
32 public void onResume() { /*...*/}
33 public void onPause() { /*...*/}
34 public void onStop() { /*...*/}
35 public void onDestroy() { /*...*/}
36}
1<?xml version="1.0" encoding="utf-8"?>
2<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="ch.android.com"
4 android:versionCode="1"
5 android:versionName="1.0">
6 <uses-sdk android:minSdkVersion="10" />
7
8 <application android:icon="@drawable/icon" android:label="@string/app_name">
9 <activity android:name=".AndroidLernenActivity"
10 android:label="@string/app_name">
11 <intent-filter>
12 <action android:name="android.intent.action.MAIN" />
13 <category android:name="android.intent.category.LAUNCHER" />
14 </intent-filter>
15 </activity>
16 <activity android:name=".Activity2"
17 android:label="Activity2">
18 <intent-filter >
19 <action android:name="ch.android.Activity2" />
20 <category android:name="android.intent.category.DEFAULT" />
21 </intent-filter>
22 </activity>
23 </application>
24</manifest>
2<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="ch.android.com"
4 android:versionCode="1"
5 android:versionName="1.0">
6 <uses-sdk android:minSdkVersion="10" />
7
8 <application android:icon="@drawable/icon" android:label="@string/app_name">
9 <activity android:name=".AndroidLernenActivity"
10 android:label="@string/app_name">
11 <intent-filter>
12 <action android:name="android.intent.action.MAIN" />
13 <category android:name="android.intent.category.LAUNCHER" />
14 </intent-filter>
15 </activity>
16 <activity android:name=".Activity2"
17 android:label="Activity2">
18 <intent-filter >
19 <action android:name="ch.android.Activity2" />
20 <category android:name="android.intent.category.DEFAULT" />
21 </intent-filter>
22 </activity>
23 </application>
24</manifest>
main.xml:
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent" >
6 <TextView
7 android:layout_width="fill_parent"
8 android:layout_height="wrap_content"
9 android:text="@string/hello" />
10 <Button
11 android:id="@+id/ButtonTest"
12 android:layout_width="fill_parent"
13 android:layout_height="wrap_content"
14 android:text="@string/Button" />
15
16</LinearLayout>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent" >
6 <TextView
7 android:layout_width="fill_parent"
8 android:layout_height="wrap_content"
9 android:text="@string/hello" />
10 <Button
11 android:id="@+id/ButtonTest"
12 android:layout_width="fill_parent"
13 android:layout_height="wrap_content"
14 android:text="@string/Button" />
15
16</LinearLayout>
strings.xml:
1<?xml version="1.0" encoding="utf-8"?>
2<resources>
3 <string name="hello">Hello World, AndroidLernenActivity!</string>
4 <string name="app_name">AndroidLernen</string>
5 <string name="Button">Dies ist ein Knopf</string>
6</resources>
2<resources>
3 <string name="hello">Hello World, AndroidLernenActivity!</string>
4 <string name="app_name">AndroidLernen</string>
5 <string name="Button">Dies ist ein Knopf</string>
6</resources>
Activity2.xml:
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent" >
6 <TextView
7 android:layout_width="fill_parent"
8 android:layout_height="wrap_content"
9 android:text="This is Activity 2" />
10</LinearLayout>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent" >
6 <TextView
7 android:layout_width="fill_parent"
8 android:layout_height="wrap_content"
9 android:text="This is Activity 2" />
10</LinearLayout>
Activity2.java:
1package ch.android.com;
2import android.app.Activity;
3import android.os.Bundle;
4public class Activity2 extends Activity {
5 @Override
6 public void onCreate(Bundle savedInstanceState) {
7 super.onCreate(savedInstanceState);
8 setContentView(R.layout.activity2);
9 }
10}
2import android.app.Activity;
3import android.os.Bundle;
4public class Activity2 extends Activity {
5 @Override
6 public void onCreate(Bundle savedInstanceState) {
7 super.onCreate(savedInstanceState);
8 setContentView(R.layout.activity2);
9 }
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.