ich arbeite gerade das offizielle Android Tutorial ab und komme an dieser stelle nicht weiter: developer.android.com/training…pp/starting-activity.html
Die sendMessage Funktion wird bei mir nicht aufgerufen. Keine Fehler beim Compilieren und auch keine Exceptions während ich es auf dem Handy ausführe und auf den Button klicke. Habt Ihr einen Anhaltspunkt für mich?
So sieht mein Code aus:
XML-Quellcode
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
- <EditText android:id="@+id/edit_message"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="@string/edit_message" />
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/button_send" />
- android:onClick="sendMessage" />
- </LinearLayout>
Quellcode
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void test() {
- AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
- dlgAlert.setMessage("This is an alert with no consequence");
- dlgAlert.setTitle("App Title");
- dlgAlert.setPositiveButton("OK", null);
- dlgAlert.setCancelable(true);
- dlgAlert.create().show();
- }
- /** Called when the user clicks the Send button */
- public void sendMessage(View view) {
- test();
- Intent intent = new Intent(this, DisplayMessageActivity.class);
- EditText editText = (EditText) findViewById(R.id.edit_message);
- String message = editText.getText().toString();
- intent.putExtra(EXTRA_MESSAGE, message);
- startActivity(intent);
- }
- }