Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Activity.Main
-----------------------------------------------------------------------------------
-------------------------------
<?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"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/respuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="#E91E63"
android:textSize="30sp" />
<EditText
android:id="@+id/numero1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Escribe un numero"
android:inputType="number" />
<EditText
android:id="@+id/numero2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Escribe un numero"
android:inputType="number" />
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_suma"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Suma" />
<Button
android:id="@+id/button_resta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Resta" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_division"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="División" />
<Button
android:id="@+id/button_multiplicacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Multiplicación" />
</TableRow>
</TableLayout>
</LinearLayout>
MainActivity
-----------------------------------------------------------------------------------
------------------------------
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text_respuesta = findViewById(R.id.respuesta);
edit_numero_uno = findViewById(R.id.numero1);
edit_numero_dos = findViewById(R.id.numero2);
btn_suma = findViewById(R.id.button_suma);
btn_suma.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btn_division = findViewById(R.id.button_division);
btn_division.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
btn_multiplicacion = findViewById(R.id.button_multiplicacion);
btn_multiplicacion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
btn_resta = findViewById(R.id.button_resta);
btn_resta.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
public double suma (int a, int b){
return a+b;
}
if (b!=0){
respuesta=a/b;
}
return respuesta;
}
}