Use Andriod studio, Java Display the screen with corresponding food items. For example, the vegetable screen will display kale, onions,.... Use check boxes to show the food items. Then selected checkbox food item and prices will be displayed on checkout screen(another activity)
(send values(total price, name) of checked checkboxes in one activity to another activity)
Below is what I have now
public class Vegetables extends FoodTypesMenu {
CheckBox cb1, cb2, cb3, cb4;
String name = "";
String vegprice = "";
double vegPrice = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vegetables);
}
public void onCheckboxClicked(View view) {
//Is the button now checked?
boolean checked = ((CheckBox) view).isChecked();
Button btnNext = (Button) findViewById(R.id.bn1);
switch (view.getId()) {
case R.id.onion_cb:
if(checked){
name="Onion";
vegPrice += 5;
}
break;
case R.id.carrot_cb:
if(checked){
name="Carrot";
}
break;
case R.id.spinach_cb:
if(checked){
name="Spinach";
}
break;
case R.id.garlic_cb:
if(checked){
name="Garlic";
}
break;
}
}
public void tocheckout(View v) {
Intent intent = new Intent(this, CheckOut.class);
intent.putExtra("Name", name);
startActivity(intent);
startActivity(intent);
}
}
```
```
public class CheckOut extends FoodTypesMenu {
String name = "";
String price = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_out);
String name = getIntent().getStringExtra("Name");
}
public void OnClickButton (View view){
Intent intent2 = new Intent(this, Payment.class);
this.startActivity(intent2);
}
}
The string name is not displayed and also don't know how to display total price of checked boxes on another activity
[enter image description here][2]
[1]: https://i.stack.imgur.com/Mag7P.png
[2]: https://i.stack.imgur.com/1kw6X.png
Aucun commentaire:
Enregistrer un commentaire