How do I get the value of a selected checkbox in mainActivity3 and 4 and show this selected item in a textView in main Activity1?

1

I'm doing a college job where I have to develop an application for ordering in a bar, I've created 5 activity where the first one is a home screen and the other checkboxes with orders, how do I get the selected items in the checkbox of all main activity and show them in mainactivity1? And also how do I determine a "price" for each checkbox where in the last activity I can show the total value of all checkboxes selected?

    
asked by anonymous 28.03.2018 / 01:23

1 answer

0

To get the value of the checkbox, you check if it is checked and assigns a reference value, eg: [x] Beer:

   String valores;
   if(cerveja.isChecked()){
      valores += "1";
   }

So if you have another check you will add the values, but then you say: As this 1 can identify which beer was marked, as it has more checkbox the string can be: values="12354"; then as each value represents an item, you do:

  //Isso aqui na outra activity
  if(valores.contais("1")){
     //cerveja tava marcado
  }

But if you want to get the checkbox text you do:

 String valor = checkbox.getText().toString();

To pass values between activities you use this:

 Intent it = new Intent(context, proximaAcitivy.class);
          //Cada chave deve ser unica
          it.putExtra("chave", valor);
          startActivity(it);

In the other activity to recover you do:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

 Intent intent = getIntent();
 String text = intent.getStringExtra("chave");

 }

On the prices, every checkbox is checked, you save the values and move to another activity and sum to the next value, make the next msm until you reach the last

    
28.03.2018 / 01:41