我有一个包含景点列表的微调器。我想使用 switch case 语句来根据用户选择的吸引力来更改显示的图像。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.attractions_layout);
ArrayAdapter<String> attractionsAdapter = new ArrayAdapter<String> (Attractions.this, android.R.layout.simple_spinner_item, attractionEntries);
attractionsSpinner = (Spinner) findViewById (R.id.spinnerAttractions);
attractionsSpinner.setAdapter(attractionsAdapter);
attractionsSpinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent,View view, int position, long id) {
// TODO Auto-generated method stub
int pos = attractionsSpinner.getSelectedItemPosition();
ImageView imageView = (ImageView) findViewById(R.id.imageViewAttraction);
String[] information = getResources().getStringArray(R.array.attractions_information_collection);
switch (position)
{
case 0:
image = R.drawable.avenue_of_stars;
imageView.setImageResource(image);
break;
case 1:
image = R.drawable.disneyland_fountain;
imageView.setImageResource(image);
break;
}
}
我收到一条错误消息,提示“无法将图像解析为变量”