Skip to content

Instantly share code, notes, and snippets.

@behrends
Created January 17, 2022 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save behrends/1527f8061fb7b11efd6ecbe7b1224f97 to your computer and use it in GitHub Desktop.
Save behrends/1527f8061fb7b11efd6ecbe7b1224f97 to your computer and use it in GitHub Desktop.
TIF19 - Toast mit Titel
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