如何根据 android studio 中的微调器选择更改 imageview 视图?

how to change imageview view based on spinner selection in android studio?

我正在尝试根据微调器选择在图像视图中显示图像。如果有人知道如何解决这个问题,请帮助。

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
            }

        });