Contenidos
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<!-- activity_main.xml --> <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="vertical" android:padding="16dp" tools:context=".MainActivity"> <EditText android:id="@+id/editTextName" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Nombre" android:inputType="textPersonName" /> <EditText android:id="@+id/editTextEmail" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Correo electrónico" android:inputType="textEmailAddress" /> <Button android:id="@+id/buttonSubmit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Enviar" /> </LinearLayout> |
MainActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package com.example.myapplication import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.EditText import android.widget.Toast // MainActivity.kt class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val editTextName = findViewById<EditText>(R.id.editTextName) val editTextEmail = findViewById<EditText>(R.id.editTextEmail) val buttonSubmit = findViewById<Button>(R.id.buttonSubmit) buttonSubmit.setOnClickListener { val name = editTextName.text.toString() val email = editTextEmail.text.toString() // Mostrar los valores en un Toast val toastMessage = "Nombre: $name\nCorreo electrónico: $email" Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show() } } } |