How do I take the value of a checkbox selected on mainActivity3 and 4 and display this selected item in a textView in main Activity1?

Asked

Viewed 918 times

1

I’m doing a college job where I have to develop an application for orders in a bar, already created 5 Activity where the first and a home screen and the other order screens with checkbox, How do I pick up the selected items in the checkbox of all main Activity and show them on 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 selected checkbox?

1 answer

0

To get the checkbox value, you check if it is checked and assign a reference value, e.g.: [x] Beer:

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

If you have another check you add the values, but then you say: As this 1 can identify which beer was marked, as 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 text of the checkbox you do:

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

To pass values between activitys 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");

 }

About the prices, every check of which checkbox is marked, you save the values and passes to another Activity and the sum with the next value, makes the msm in the next until you arrive at the last

Browser other questions tagged

You are not signed in. Login or sign up in order to post.