[英]How do I associate numbers with my array list?
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 并在微调器中使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.