我正在尝试根据微调框的选择在图像视图中显示图像。如果有人知道如何解决此问题,请提供帮助。
public class activity_tables extends AppCompatActivity {
Spinner s1;
String[] tbls;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tables);
s1 = (Spinner)findViewById(R.id.spinner);
tbls = getResources().getStringArray(R.array.tables);
final ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,tbls);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
}
}
像这样为您的微调器设置onItemSelectedListener
s1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// your code here
if(position==0)
{
qImageView.setImageResource(R.drawable.whatever);}
else if(position ==1)
{
qImageView.setImageResource(R.drawable.whatever);}
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});