Creacion interfaz grafica

Para esta actividad se realiza una app que contenga Group Box, botones, TextView, Radio Buttons y CheckBoxes.




CODIGO.

  1. package com.example.app_compras_groupbox;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.os.Bundle;
  6. import android.provider.MediaStore;
  7. import android.view.View;
  8. import android.widget.CheckBox;
  9. import android.widget.RadioButton;
  10. import android.widget.TextView;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.     TextView tvResultado;
  14.     CheckBox cbImpresora, cbEscritorio, cbAuriculares;
  15.     RadioButton rbAcer, rbMSI, rbLenovo;
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.         tvResultado = (TextView) findViewById(R.id.tvResultado);
  21.         cbImpresora = (CheckBox) findViewById(R.id.cbImpresora);cbAuriculares = (CheckBox) findViewById(R.id.cbAuriculares);
  22.         cbEscritorio = (CheckBox) findViewById(R.id.cbEscritorio);
  23.         rbAcer = (RadioButton) findViewById(R.id.rbAcer); rbLenovo = (RadioButton) findViewById(R.id.rbLenovo); rbMSI = (RadioButton) findViewById(R.id.rbMSI);
  24.     }
  25.  
  26.     public void Calcular(View view){
  27.         int precio = 0;
  28.         if (rbAcer.isChecked())
  29.         {
  30.             precio = 0;
  31.             precio = 2200000;
  32.             if (cbEscritorio.isChecked()){precio += 150000;}
  33.             if (cbImpresora.isChecked()){precio += 450000;}
  34.             if (cbAuriculares.isChecked()){precio += 300000;}
  35.         }
  36.         if (rbMSI.isChecked())
  37.         {
  38.             precio = 0;
  39.             precio = 3500000;
  40.             if (cbEscritorio.isChecked()){precio += 150000;}
  41.             if (cbImpresora.isChecked()){precio += 450000;}
  42.             if (cbAuriculares.isChecked()){precio += 300000;}
  43.         }
  44.         if (rbLenovo.isChecked())
  45.         {
  46.             precio = 0;
  47.             precio = 1500000;
  48.             if (cbEscritorio.isChecked()){precio += 150000;}
  49.             if (cbImpresora.isChecked()){precio += 450000;}
  50.             if (cbAuriculares.isChecked()){precio += 300000;}
  51.         }
  52.         String valor = String.valueOf(precio);
  53.         tvResultado.setText(valor);
  54.     }
  55.  
  56.     public void Solo1(View view)
  57.     {
  58.         if(rbLenovo.isChecked())
  59.         {
  60.             rbAcer.setChecked(false);rbMSI.setChecked(false);
  61.         }
  62.         if(rbAcer.isChecked())
  63.         {
  64.         rbLenovo.setChecked(false);rbMSI.setChecked(false);
  65.         }
  66.         if(rbMSI.isChecked())
  67.         {
  68.             rbAcer.setChecked(false);rbLenovo.setChecked(false);
  69.         }
  70.  
  71.     }
  72. }



Comentarios