Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Pl 02-codigo-calculadora

207 views

Published on

Práctica de Android Studio - Aplicaciones Móviles

Published in: Education
  • Be the first to comment

  • Be the first to like this

Pl 02-codigo-calculadora

  1. 1. IESTP “RAMON COPAJA” Lic. Noé ARPASI JIMENEZ -1- U.D. “Aplicaciones Móviles” PROYECTO: CALCULADORA 1. INTERFAZ: activity_main.xml 2. CODIGO: ManiActivity.java package ga.gestionweb.calculadora1; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends AppCompatActivity { EditText txtnum1, txtnum2; Button btnS, btnR, btnM, btnD; TextView txtRes; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtnum1 = (EditText) findViewById(R.id.txtn1); txtnum2 = (EditText) findViewById(R.id.txtn2); btnS = (Button) findViewById(R.id.btnSuma); btnR = (Button) findViewById(R.id.btnResta); btnM = (Button) findViewById(R.id.btnMultiplicacion); btnD = (Button) findViewById(R.id.btnDivision); txtRes = (TextView) findViewById(R.id.txtResultado);
  2. 2. IESTP “RAMON COPAJA” Lic. Noé ARPASI JIMENEZ -2- U.D. “Aplicaciones Móviles” btnS.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int num1=Integer.parseInt(txtnum1.getText().toString()); int num2=Integer.parseInt(txtnum2.getText().toString()); int suma=num1+num2; txtRes.setText("Resultado : "+suma); } }); btnR.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int num1=Integer.parseInt(txtnum1.getText().toString()); int num2=Integer.parseInt(txtnum2.getText().toString()); int suma=num1-num2; txtRes.setText("Resultado : "+suma); } }); btnM.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int num1=Integer.parseInt(txtnum1.getText().toString()); int num2=Integer.parseInt(txtnum2.getText().toString()); int suma=num1*num2; txtRes.setText("Resultado : "+suma); } }); btnD.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int num1 = Integer.parseInt(txtnum1.getText().toString()); int num2 = Integer.parseInt(txtnum2.getText().toString()); int suma = num1 / num2; txtRes.setText("Resultado : " + suma); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; }
  3. 3. IESTP “RAMON COPAJA” Lic. Noé ARPASI JIMENEZ -3- U.D. “Aplicaciones Móviles” @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }

×