You are on page 1of 4

UNIVERSIDAD PRIVADA FRANZ TAMAYO

FACULTAD DE INGENIERIA

CARRERA DE INGENIERIA EN SISTEMAS

Laboratorio 1 - Intents con Parámetros

INTEGRANTES: JORGE CARLOS ROJAS CALLA

MATERIA: PROGRAMACIÓN DE DISPOSITIVOS MOVILES

SEMESTRE: SEPTIMO

LA PAZ-BOLIVIA
2021
2023
1

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="horizontal">

<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Usuario"
android:inputType="text"
android:padding="16dp" />

<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Contraseña"
android:inputType="textPassword"
android:padding="16dp" />

<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ingresar"
android:onClick="login" />

<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
tools:layout_editor_absoluteX="-16dp"
tools:layout_editor_absoluteY="0dp" />

</LinearLayout>
2

MainActivity.kt:

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View

var Nothing?.text: Any


get() {
TODO("Not yet implemented")
}
set(value) {}

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
fun login(view: View) {
val editTextUsername = null
val username = editTextUsername.text.toString()
val editTextPassword = null
val password = editTextPassword.text.toString()

if (username == "alfred" && password == "1234") {


val intent = Intent(this, WelcomeActivity::class.java)
intent.putExtra("password", password)
startActivity(intent)
} else {
val textViewResult = null
textViewResult.text = "Acceso Incorrecto"
}
}

}
}

WelcomeActivity.kt:

package com.example.laboratorio

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class WelcomeActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_welcome)
3

val password = intent.getStringExtra("password")


val textViewWelcome = null
textViewWelcome.text = "Bienvenido $password"
}
}

activity_welcome.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textViewWelcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp" />

</LinearLayout>

You might also like