這裏是我的代碼,我想將微調器的值與數組值相乘。將微調值與數組值相乘
該陣列由命名爲Constant
我其他的Java類獲取其值和類有一個數組food calories
:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.items_details);
Spinner mspin=(Spinner) findViewById(R.id.spinner1);
Integer[] items = new Integer[]{1,2,3,4};
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,android.R.layout.simple_spinner_item, items);
mspin.setAdapter(adapter);
TextView name_select=(TextView)findViewById(R.id.SelectedName);
name_select.setText(constant.food_items[constant.SelectedIndex]);
imageView = (ImageView) findViewById(R.id.imagedetail);
UpdateImage(constant.food_items[constant.SelectedIndex]);
TextView calories=(TextView)findViewById(R.id.calories111);
calories.setText(constant.food_calories[constant.index]+"");
int multiple=0;
{
try {multiple= mspin.getSelectedItemPosition()* constant.food_calories[constant.index];
TextView tot_calories=(TextView)findViewById(R.id.caloriestotal);
tot_calories.setText(multiple+"");}
catch(NumberFormatException nfe) {
Log.e("Error", "Failed to multiply invalid non-numbers");
}
恆類代碼
public static final Integer[] food_calories=new Integer[]{74
};
public static int index = 0;
}
什麼是您的常數班?添加此類代碼。 –
@HaniyehKhaksar看到這個不變的類代碼 – user3343999
你的數組中沒有任何數據! –