Está en la página 1de 12

PROYECTO004

PASOS:
1.- Debemos
crear un
nuevo
proyecto,
para eso hay
que irnos a
FILE,
despus
NEW y para
finalizar
damos clic a
ANDROID
APPLICATION
PROJECT.
2.- Una vez teniendo ya
el proyecto creado
arrastraremos la opcin
TEXTVIEW y la
pondremos en la
pantalla de
PROGRAMA5.
Agregaremos 3.
Dndoles doble clic le
cambiaremos el
nombre.
3.- Ahora
seleccionaremos TEXT
FIELDS y
arrastraremos la
opcin ABC y la
pondremos en la
pantalla de
PROGRAMA4
Agregaremos 2.
4.- Cambiaremos las
propiedades de ABC,
en ID pondremos
@+id/et1 y
volveremos a repetir
el mismo para el que
falta, para el segundo
seria @+id/et2.
5.- Ahora
agregaremos un
botn para eso hay
que irnos a FORM
WIDGETS, despus
arrastraremos la
opcin BUTTON a la
pantalla de
PROGRAMA4.
6.- Despus
iremos a
MAINACTIVI
TY.JAVA, nos
saldr una
pantalla con
su cdigo el
cual
borraremos
y
pondremos
el siguiente:
package com.example.programa4;
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);
}

}
}
Con el cdigo pasada ya nos saldran los
RADIOBUTTON
7.-Despus
guardaremo
s el
proyecto
8.-
Despus
ejecutarem
os el
programa.
9.- Ya tendramos
creado el programa.

También podría gustarte