I have created two spinners, a meal type spinner (eg Breakfast, lunch...) and a food spinner (eg porridge). Once the user has selected their meal type the associated foods appear in the second spinner.
Now I want to be able to create a food calculator which will multiply a set of calories for each food with a number entered by the user but I'm not sure how I associate my numbers with my array list for my spinner. Is it something like this?
private void chooseBreakfast() {
planspinner1 = (Spinner) findViewById(R.id.planspinner);
List<String> planlist = new ArrayList<String>();
planlist.add("Porridge-40g/140cal");
planlist.add("Coffee-10g/10cal");
planlist.add("Toast-30g/87cal");
ArrayAdapter<String> planAdapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, planlist);
planAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
planspinner1.setAdapter(planAdapter1);
ArrayList<int> food = newArrayList<int>();
food.add(4);
food.add(1);
food.add(3);
}
do a list objects using a food class like
{
private string name;
private int id;
private double calories
}
and use that in your spinner
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.