I am creating an app that allow user to make their own selection
May i know how to make it calculate? It seems like the price is not include when radio button or checkbox is clicked. Please help me. is it logically wrong or the syntax is wrong?
radioGroup1=(RadioGroup)findViewById(R.id.radioGroup_1);
radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
String tempSize="Choose your size";
double SPrice=0;
switch (radioGroup1.getCheckedRadioButtonId())
{
case R.id.radioButton_munch:
tempSize="Personal Pan";
SPrice=5;
break;
case R.id.radioButton_hungry:
tempSize="Regular Pan";
SPrice=9;
break;
case R.id.radioButton_horse:
tempSize="Large Pan";
SPrice=12;
break;
}Size.setText(tempSize);
SizePrice = SPrice;
}
});
checkBoxListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Topping = (TextView)findViewById(R.id.textView_TopAns);
Topping.setText(" ");
if(ChkCheese.isChecked()){
Topping.setText(Topping.getText().toString() + ChkCheese.getText().toString());
ToppingPrice=2.5;
}
if(ChkMushroom.isChecked()){
Topping.setText(Topping.getText().toString() + "," + ChkMushroom.getText().toString());
ToppingPrice=1;
}
} ;
ChkCheese.setOnClickListener(checkBoxListener);
ChkMushroom.setOnClickListener(checkBoxListener);
TotalPrice = SizePrice + CrustPrice + ToppingPrice;
Price.setText("$" + TotalPrice );
}
}
Aucun commentaire:
Enregistrer un commentaire