private String[] genre = { "Action", "Adventure", "Comedy", "Biography", "Drama", "Family", "Horror", "Romance" };
private Integer images[] = { R.drawable.img_action, R.drawable.img_adventure, R.drawable.img_biografy, R.drawable.img_comedy, R.drawable.img_drama, R.drawable.img_family, R.drawable.img_horror, R.drawable.img_romantis };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setInitialImage();
spinner = (Spinner) findViewById(R.id.label_spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>( // make array adapter
this, android.R.layout.simple_spinner_item, genre
);
spinner.setAdapter(adapter); // connect adapter with spinner
spinner.setOnItemSelectedListener(new OnItemSelectedListener() { // get item from spinner
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
int index = spinner.getSelectedItemPosition();
if () {
currImage = images[0];
Toast.makeText(getBaseContext(), "Anda memilih genre film "+ genre[index], Toast.LENGTH_SHORT)
.show();
}
setCurrentImage(); // called method
}
});
}
当我点击其中一个微调器项目时,将显示电影类型的图像。 我应该在if语句中键入什么内容?
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
将onItemSelectedMethod
修改为
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
currImage = images[position];
Toast.makeText(getBaseContext(), "Anda memilih genre film "+ genre[index], Toast.LENGTH_SHORT)
.show();
setCurrentImage(); // called method
}