operaciones con spinner (1)

14
OPERACIONES ARITMETICAS UTILIZANDO SPINNER EDITH YAMILETH GONZALEZ CARO JORGE ENRIQUE SANTIAGO GARCIA

Upload: manuel-gutierrez

Post on 14-Apr-2017

105 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Operaciones con spinner (1)

OPERACIONES ARITMETICAS UTILIZANDO SPINNEREDITH YAMILETH GONZALEZ CAROJORGE ENRIQUE SANTIAGO GARCIA

Page 2: Operaciones con spinner (1)

PRIMERO CREAMOS UN NUEVO ARCHIVO DE TIPO PROYECTO DE APLICACIÓN ANDROID

Page 3: Operaciones con spinner (1)

LE DAMOS UN NOMBRE A NUESTRO PROGRAMA Y SEGIDAMENTE PRESIONAREMOS “NEXT”HASTA QUE FINALIZEMOS

Page 4: Operaciones con spinner (1)

ELIMINAMOS EL HELLO WORLD

Page 5: Operaciones con spinner (1)

CREAMOS DOS TEXT VIEW Y DOS PAIN TEXT A LOS QUE LES CAMBIAREMOS EL ID POR “et1”y”et2”

Page 6: Operaciones con spinner (1)

AGREGAMOS UN SPINNER

Page 7: Operaciones con spinner (1)

CREAREMOS UN BOTON AL QUE LE DAREMOS LA ACCION Y EL NOMBRE DE OPERAR

Page 8: Operaciones con spinner (1)

AGREGAMOS ESTE CODIGO:

package com.example.programa7_bis; import com.example.programa7_bis.R; 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.Spinner;import android.widget.ArrayAdapter; public class MainActivity extends Activity {            private Spinner spinner1;           

Page 9: Operaciones con spinner (1)

 @Override            protected void onCreate(Bundle savedInstanceState) {                        super.onCreate(savedInstanceState);                        setContentView(R.layout.activity_main);                                               spinner1 = (Spinner) findViewById(R.id.spinner1);                String []opciones={"sumar","restar","multiplicar","dividir"};                       ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, opciones);                spinner1.setAdapter(adapter);            } 

Page 10: Operaciones con spinner (1)

 @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);                 int nro1=Integer.parseInt(et1.getText().toString());        int nro2=Integer.parseInt(et2.getText().toString());            String selec=spinner1.getSelectedItem().toString();       

Page 11: Operaciones con spinner (1)

 if (selec.equals("sumar")) {            int suma=nro1+nro2;             String resu=String.valueOf(suma);             tv3.setText(resu);        }        else            if (selec.equals("restar")) {                int resta=nro1-nro2;                String resu=String.valueOf(resta);                tv3.setText(resu);            }            else                if (selec.equals("multiplicar")) {                    int multi=nro1*nro2;                    String resu=String.valueOf(multi);                    tv3.setText(resu);                }                else                    if (selec.equals("dividir")) {                        int divi=nro1/nro2;                        String resu=String.valueOf(divi);                        tv3.setText(resu);                    }            }}

Page 12: Operaciones con spinner (1)

DE ESTA FORMA SE MOSTRARA ,SI HUBIERA ERRORES DEBEMOS SOLUCIONARLOS

Page 13: Operaciones con spinner (1)

Y FINALMENTE QUEDARA DE ESTA FORMA

Page 14: Operaciones con spinner (1)

CONCLUSION• LAS OPERACIONES CON SPINNER SON DISTINTAS YA

QUE NO NECESITAMOS CONFIGURARLO COMO LOS BOTONES O LOS TEXTVIEW ,LOS SPINNER SE CONFIGURAN EN EL CODIGO,ES UNA FORMA DISTITA AL DE LOS CHECHBOX ,CREO QUE CADA VEZ RENDEMOS ALGO NUEVO

• -EDITH YAMILETH GONZALEZ CARO