RadioButton and CheckBox Automatically Display After Clicked

Viewed 33

Hello I am making a order page for individual items on the menu.

My problem is when I click a RadioButton and CheckBox the price does not show. I have to press the quantity button for it to appear.

Also when I press another RadioButton and CheckBox it stays from the previous price. And wilw only change when I press the quanitiy button again.

Here is the Java Code RadioButton:

    plusquantity.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int radioID = radioG.getCheckedRadioButtonId();
            if(radioID == R.id.hotradioButton){
                int basePrice = 100;
                quantity++;
                displayQuantity();
                int coffePrice = basePrice * quantity;
                String setnewPrice = String.valueOf(coffePrice);
                coffeePrice.setText(setnewPrice);

                int ifCheckBox = CalculatePrice(addCream1, addSyrup, addNata,addJelly);
                coffeePrice.setText("P " + ifCheckBox);


            }else if(radioID == R.id.coldRadioButton){

                int basePrice = 140;
                quantity++;
                displayQuantity();
                int coffePrice = basePrice * quantity;
                String setnewPrice = String.valueOf(coffePrice);
                coffeePrice.setText(setnewPrice);

                int ifCheckBox = CalculatePrice2(addCream1, addSyrup, addNata,addJelly);
                coffeePrice.setText("P " + ifCheckBox);

            }else if(radioID == R.id.blendRadioButton){

                int basePrice = 150;
                quantity++;
                displayQuantity();
                int coffePrice = basePrice * quantity;
                String setnewPrice = String.valueOf(coffePrice);
                coffeePrice.setText(setnewPrice);

                int ifCheckBox = CalculatePrice3(addCream1, addSyrup, addNata,addJelly);
                coffeePrice.setText("P " + ifCheckBox);

            }


        }
        private void displayQuantity() {
            quantitynumber.setText(String.valueOf(quantity));
        }

    });

    
    minusquantity.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int radioID = radioG.getCheckedRadioButtonId();
            if (radioID == R.id.hotradioButton) {
                int basePrice = 100;

                if (quantity == 0) {
                    Toast.makeText(Espresso_Item1.this, "Cannot Decrease Quantity", 
        Toast.LENGTH_SHORT).show();
                } else {

                    quantity--;
                    displayQuantity();
                    int coffePrice = basePrice * quantity;
                    String setnewPrice = String.valueOf(coffePrice);
                    coffeePrice.setText(setnewPrice);

                    int ifCheckBox = CalculatePrice(addCream1, addSyrup, addNata,addJelly);
                    coffeePrice.setText("P " + ifCheckBox);



                }
            }else if (radioID == R.id.coldRadioButton){
                int basePrice = 140;


                if (quantity == 0) {
                    Toast.makeText(Espresso_Item1.this, "Cannot Decrease Quantity", 
         Toast.LENGTH_SHORT).show();
                } else {

                    quantity--;
                    displayQuantity();
                    int coffePrice = basePrice * quantity;
                    String setnewPrice = String.valueOf(coffePrice);
                    coffeePrice.setText(setnewPrice);

                    int ifCheckBox = CalculatePrice2(addCream1, addSyrup, addNata,addJelly);
                    coffeePrice.setText("P " + ifCheckBox);


                }

            }else if(radioID == R.id.blendRadioButton){
                int basePrice = 150;


                if (quantity == 0) {
                    Toast.makeText(Espresso_Item1.this, "Cannot Decrease Quantity", Toast.LENGTH_SHORT).show();
                } else {

                    quantity--;
                    displayQuantity();
                    int coffePrice = basePrice * quantity;
                    String setnewPrice = String.valueOf(coffePrice);
                    coffeePrice.setText(setnewPrice);

                    int ifCheckBox = CalculatePrice3(addCream1, addSyrup, addNata,addJelly);
                    coffeePrice.setText("P " + ifCheckBox);


                }

            }
        }

        private void displayQuantity() {
            quantitynumber.setText(String.valueOf(quantity));
        }
    });

}

CheckBox Java Code:

  private int CalculatePrice3(CheckBox addCream1, CheckBox addSyrup, CheckBox addNata, 
  CheckBox addJelly) {
    int basePrice = 150;

    if (addCream1.isChecked()) {

        basePrice = basePrice + 20;
    }

    if (addSyrup.isChecked()) {

        basePrice = basePrice + 20;
    }

    if (addNata.isChecked()) {

        basePrice = basePrice + 20;
    }
    if (addJelly.isChecked()) {

        basePrice = basePrice + 20;
    }

    return basePrice * quantity;
}

    private int CalculatePrice2(CheckBox addCream1, CheckBox addSyrup, CheckBox addNata, 
  CheckBox addJelly) {
    int basePrice = 140;

    if (addCream1.isChecked()) {

        basePrice = basePrice + 20;
    }

    if (addSyrup.isChecked()) {

        basePrice = basePrice + 20;
    }

    if (addNata.isChecked()) {

        basePrice = basePrice + 20;
    }
    if (addJelly.isChecked()) {

        basePrice = basePrice + 20;
    }

    return basePrice * quantity;
   }

  private int CalculatePrice(CheckBox addCream, CheckBox addSyrup, CheckBox addNata, CheckBox 
  addJelly) {

    int basePrice = 100;

    if (addCream1.isChecked()) {

        basePrice = basePrice + 20;
    }

    if (addSyrup.isChecked()) {

        basePrice = basePrice + 20;
    }

    if (addNata.isChecked()) {

        basePrice = basePrice + 20;
    }
    if (addJelly.isChecked()) {

        basePrice = basePrice + 20;
    }

    return basePrice * quantity;
}

private void displayQuantity() {
    quantitynumber.setText(String.valueOf(quantity));
}

Here is the design of the page for a visual reference: https://postimg.cc/YvWtnwCK

Any help is appreicated!

0 Answers
Related