james
james

Reputation: 2663

Android Spinners And Buttons

I have an array of Buttons and Array with my Spinners.I am trying to set the Buttons text to the selected Spinners Text.Can't seem to figure out how to do this.

for(int i=0;i<theSpinners.length;i++){
       theSpinners[i].setSelection(theArray[i]);
       theButtons[i].setText(theSpinners[i].getSelectedItemPosition());
}

Hope this makes sense.

Upvotes: 1

Views: 363

Answers (1)

Cristian
Cristian

Reputation: 200080

getSelectedItemPosition() returns an integer, so setText won't behave as you want. You will want do do something like this...

theButtons[i].setText(String.valueOf(theSpinners[i].getSelectedItemPosition()));

... if what you want is setting the index of the spinner. Or maybe, you want to use the getSelectedItem method...

theButtons[i].setText(theSpinners[i].getSelectedItem().toString());

Upvotes: 1

Related Questions