0

I'm developing an application for android on accessibility and need to dynamically load the images of the buttons according to a spinner chosen. Attached is a photo application. Most of the photos have a spinner empty. When it is clicked, a list would appear and so were chosen something the spinner, the button images would change. Example: Spinner - Bathroom (Images of possibilities this place) Spinner - Kitchen (Images of possibilities this place).

OBS:I chose not to use imagebutton to be easier to manipulate buttons.!

Code buttons:

 <Button
    android:id="@+id/pic1"
    android:layout_column="2"
    android:layout_columnSpan="3"
    android:layout_gravity="left"
    android:layout_row="2"
    android:drawableBottom="@drawable/pic1"
    android:text="@string/pic1" />

Application

4

2 回答 2

0

实现一个 OnItemSelectedListener 并使用方法 spinner.setOnItemSelectedListener() 将其附加到您的微调器。

然后,您可以在侦听器的 onItemSelected() 函数中设置图像。

于 2013-11-07T23:02:10.280 回答
0

希望这可以帮助

public class myActivity extends Activity implements OnItemSelectedListener {
    int[] images = {R.drawable.image01, R.drawable.image02, R.drawable.image03};
    Spinner spinner;
    Button button;

    ...
    private void setView(){
        button = (Button)findViewById(R.id.button);
        spinner = (Spinner)findViewById(R.id.spinner);
        // Register the listener
        spinner.setOnClickListener(myActivity.this);
    }

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        // Set the background of the button
        button.setBackgroundResource(images[pos]);
    }

    public void onNothingSelected(AdapterView<?> parent) {
        // Another interface callback
    }
}
于 2013-11-07T23:02:50.977 回答