-
-
Save parzibyte/49e74533f79a23c7c014878f79aac2e0 to your computer and use it in GitHub Desktop.
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 me.parzibyte.imagenesmayordeedad; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// Obtener referencias | |
final EditText editTextNombre = findViewById(R.id.editText), | |
editTextEdad = findViewById(R.id.editText2); | |
Button botonEntrar = findViewById(R.id.button); | |
// Ahora escuchamos el click del botón | |
botonEntrar.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// Obtener nombre y edad como texto | |
String nombre = editTextNombre.getText().toString(), | |
edadComoString = editTextEdad.getText().toString(); | |
// Si están vacíos detenemos la ejecución de este código | |
if (nombre.isEmpty() || edadComoString.isEmpty()) return; | |
// Si no, entonces vamos a convertir la edad a entero | |
int edad = Integer.parseInt(edadComoString); | |
// Ahora vamos a mandar esos datos que tenemos a la otra actividad | |
Intent intent = new Intent(MainActivity.this, Actividad2.class); | |
// Le agregamos el nombre | |
intent.putExtra("nombre", nombre); | |
//La edad también | |
intent.putExtra("edad", edad); | |
// Lo iniciamos y nos vemos en Actividad2 | |
startActivity(intent); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment