Tutorial Operaciones Aritmeticas Utilizaondo RadioButton
-
Upload
emiliano-gonzalez-mendez -
Category
Automotive
-
view
206 -
download
0
Transcript of Tutorial Operaciones Aritmeticas Utilizaondo RadioButton
OPERACIONES ARITMETICASCETIS 109
YAMARY SÁNCHEZ RAMOSEMILIANO GONZÁLEZ MÉNDEZ
CARLOS SAMUEL GUTIÉRREZ RODRÍGUEZJUAN ALBERTO DE JESÚS GARCÍA VÁZQUEZ
4° DM PROGRAMACIONMARGARITA ROMERO ALVARADO
PASO 1:
• Primero empezamos un nuevo Android Aplication Proyect y ponemos el nombre que gusten.
PASO 2:Insertamos un relative layoutDespués radio group y automáticamente aparecerán 3 radio button, borramos 1 porque solo ocuparemos 2 después agregamos un botón que se llame CALCULAR, después agregamos tres textviewSe llamaran DAME UN NUMERO, DAME OTRO NUMERO y resultado, y por su puesto 2 textfields debajo de los 2 primeros textview.
PASO 3:• Debemos ir a Package
Explorer para poder abrir MainActivity en el cual se encuentra nuestro código
package com.example.programa5; import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.widget.EditText;import android.widget.TextView;import android.widget.RadioButton; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override
public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void operar(View view) { EditText et1=(EditText)findViewById(R.id.et1); EditText et2=(EditText)findViewById(R.id.et2); TextView tv3=(TextView)findViewById(R.id.tv3); RadioButton radio0=(RadioButton)findViewById(R.id.radio0); RadioButton radio1=(RadioButton)findViewById(R.id.radio1);
int nro1=Integer.parseInt(et1.getText().toString()); int nro2=Integer.parseInt(et2.getText().toString()); if (radio0.isChecked()==true) { int suma=nro1+nro2; String resu=String.valueOf(suma); tv3.setText(resu); } else if (radio1.isChecked()==true) { int resta=nro1-nro2; String resu=String.valueOf(resta); tv3.setText(resu); } } }
Así aparecerá el código.
PASO 5:• Ahora guardamos todos los
cambios para poder hacer el siguiente paso
PASO 6:• Por ultimo corremos el programa
yendo a la carpeta que esta en package Explorer y le damos Run As y en nuestra primera opción para poder abrir el emulador y correr nuestra aplicación para poder hacer las pruebas y LISTO!! Terminamos.
CONCLUSIÓN: • Este es un poco mas dificil a
los anteriormente vistos ya que hay errores en las codificacion, pero analizando bien, encontraras el error.
Emiliano Gonzalez Mendez 4°DM PG