如何基于android studio中的微调框选择更改imageview视图?

问题描述 投票:0回答:1

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

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);
    }
}

android android-layout android-imageview android-spinner
1个回答
0
投票

像这样为您的微调器设置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
            }

        });
© www.soinside.com 2019 - 2024. All rights reserved.