Created
January 17, 2022 14:39
-
-
Save behrends/1527f8061fb7b11efd6ecbe7b1224f97 to your computer and use it in GitHub Desktop.
TIF19 - Toast mit Titel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mynotes | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.widget.Button | |
import android.widget.EditText | |
import android.widget.Toast | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
// Layout wird von der Activity benutzt | |
// Das Layout wird "inflated" bzw. initialisiert | |
// View-Objekte zur Laufzeit erstellt | |
setContentView(R.layout.activity_main) | |
// Referenz auf EditText-Element herstellen | |
// findViewById mit passender Id aufrufen | |
val editText = findViewById<EditText>(R.id.editNoteTitle) | |
// Referenz auf Button-Element herstellen | |
// der Button ist hier ein View-Objekt | |
// findViewById mit passender Id aufrufen | |
// Java: | |
// final Button button = (Button)findViewById(R.id.button); | |
// val ==> Konstante, var ==> Variable | |
val button = findViewById<Button>(R.id.button) | |
// Java button.setOnClickLister( new .... {} ) | |
button.setOnClickListener { | |
val title = editText.text.toString() | |
Toast.makeText(this, title, Toast.LENGTH_LONG).show() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment