Zum Inhalt springen

Bearbeiten von „Android Training/Starting Another Activity

Du bearbeitest die Quelle einer übersetzbaren Seite. Bitte stelle sicher, dass du mit der folgenden Dokumentation vertraut bist:

Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird bei Bearbeitungen öffentlich sichtbar. Melde dich an oder erstelle ein Benutzerkonto, damit Bearbeitungen deinem Benutzernamen zugeordnet werden. Ein eigenes Benutzerkonto hat eine ganze Reihe von Vorteilen.

Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.

Aktuelle Version Dein Text
Zeile 2: Zeile 2:
<translate>
<translate>
<!--T:1-->
<!--T:1-->
After completing the [[Spezial:MyLanguage/Android Training/Building a Simple User Interface|previous lesson]], you have an app that shows an activity (a single screen) with a text field and a button. In this lesson, you’ll add some code to <code>MyActivity</code> that starts a new activity when the user clicks the Send button.
After completing the [[Spezial:MyLanguage/Android Training/Building a Simple User Interface|previous lesson]], you have an app that shows an activity (a single screen) with a text field and a button. In this lesson, you’ll add some code to<code>MyActivity</code> that starts a new activity when the user clicks the Send button.


== Respond to the Send Button == <!--T:2-->
== Respond to the Send Button == <!--T:2-->
# In Android Studio, from the <code>res/layout</code> directory, edit the <code>content_my.xml</code> file.
# In Android Studio, from the <code>res/layout</code> directory, edit the<code>content_my.xml</code> file.
# Add the <code>[http://developer.android.com/reference/android/view/View.html#attr_android:onClick android:onClick]</code> attribute to the <code>[http://developer.android.com/reference/android/widget/Button.html <Button>]</code> element.</translate>
# Add the <code>[http://developer.android.com/reference/android/view/View.html#attr_android:onClick android:onClick]</code> attribute to the <code>[http://developer.android.com/reference/android/widget/Button.html <Button>]</code> element.</translate>
#: ''res/layout/content_my.xml''<syntaxhighlight lang="java">
#: ''res/layout/content_my.xml''<syntaxhighlight lang="java">
Zeile 32: Zeile 32:


== Build an Intent == <!--T:5-->
== Build an Intent == <!--T:5-->
# In <code>MyActivity.java</code>, inside the <code>sendMessage()</code> method, create an <code>Intent</code> to start an activity called <code>DisplayMessageActivity</code> with the following code:</translate>
# In <code>MyActivity.java</code>, inside the <code>sendMessage()</code> method, create an <code>Intent</code> to start an activity called<code>DisplayMessageActivity</code> with the following code:</translate>
#: ''java/com.mycompany.myfirstapp/MyActivity.java''<syntaxhighlight lang="java">
#: ''java/com.mycompany.myfirstapp/MyActivity.java''<syntaxhighlight lang="java">
public void sendMessage(View view) {
public void sendMessage(View view) {
Zeile 77: Zeile 77:
#: <translate><!--T:10-->
#: <translate><!--T:10-->
For the next activity to query the extra data, you should define the key for your intent's extra using a public constant. It's generally a good practice to define keys for intent extras using your app's package name as a prefix. This ensures the keys are unique, in case your app interacts with other apps.
For the next activity to query the extra data, you should define the key for your intent's extra using a public constant. It's generally a good practice to define keys for intent extras using your app's package name as a prefix. This ensures the keys are unique, in case your app interacts with other apps.
# In the <code>sendMessage()</code> method, to finish the intent, call the <code>startActivity()</code> method, passing it the <code>Intent</code> object created in step 1.
# In the <code>sendMessage()</code> method, to finish the intent, call the <code>startActivity()</code> method, passing it the<code>Intent</code> object created in step 1.


<!--T:11-->
<!--T:11-->
Zeile 157: Zeile 157:
</syntaxhighlight>
</syntaxhighlight>
#: <translate><!--T:16-->
#: <translate><!--T:16-->
'''Note:''' If you are using an IDE other than Android Studio, your project does not contain the <code>activity_display_message</code> layout that's requested by <code>[http://developer.android.com/reference/android/app/Activity.html#setContentView(android.view.View) setContentView()]</code>. That's OK because you will update this method later and won't be using that layout.
'''Note:''' If you are using an IDE other than Android Studio, your project does not contain the<code>activity_display_message</code> layout that's requested by <code>[http://developer.android.com/reference/android/app/Activity.html#setContentView(android.view.View) setContentView()]</code>. That's OK because you will update this method later and won't be using that layout.
# To your <code>strings.xml</code> file, add the new activity's title as follows:</translate>
# To your <code>strings.xml</code> file, add the new activity's title as follows:</translate>
#: <syntaxhighlight lang="xml">
#: <syntaxhighlight lang="xml">
Bitte kopiere keine Webseiten, die nicht deine eigenen sind, benutze keine urheberrechtlich geschützten Werke ohne Erlaubnis des Urhebers!
Du gibst uns hiermit deine Zusage, dass du den Text selbst verfasst hast, dass der Text Allgemeingut (public domain) ist, oder dass der Urheber seine Zustimmung gegeben hat. Falls dieser Text bereits woanders veröffentlicht wurde, weise bitte auf der Diskussionsseite darauf hin. Bitte beachte, dass alle Android Wiki-Beiträge automatisch unter der „Creative Commons Attribution/Share-Alike Lizenz 3.0“ stehen. Falls du nicht möchtest, dass deine Arbeit hier von anderen verändert und verbreitet wird, dann klicke nicht auf „Seite speichern“.

Um das Wiki vor automatisiertem Bearbeitungsspam zu schützen, bitten wir dich, das folgende CAPTCHA zu lösen:

Abbrechen Bearbeitungshilfe (wird in einem neuen Fenster geöffnet)

Folgende Vorlagen werden auf dieser Seite verwendet:

Cookies helfen uns bei der Bereitstellung von Android Wiki. Durch die Nutzung von Android Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.