JuiCe
JuiCe

Reputation: 4201

Setting the shown value of a Spinner

Ok, so I asked this before but it was unclear I guess. I want to take a spinner filled with Strings, and change the selected item within my code, without any user interaction.

The reason for this is that my application will read in some data from another device, and then display that data for the user.

I am using spinners instead of textviews because the user has the option to select something in that spinner, and then press send, to send THAT information back to the other device.

So in the pictures below...the spinner begins on Sensitive. I would like to change it to Insensitive. But I want to do this in my CODE, so that it ends up looking like the third picture.

enter image description here enter image description here enter image description here

EDIT

int pumpTimeResult = RelayAPIModel.NativeCalls.GetParmJava( RelayAPIModel.PARM_PUMPTIME );
Log.i( "Anti-Pump", "pumpTimeResult ==" + Integer.toString( pumpTimeResult ) );
Spinner pumpTimeSpinner = (Spinner) findViewById( R.id.pumpTimeSpinner );
if( pumpTimeResult != -1 ) {
    int index = pumpTime.indexOf( Integer.toString( pumpTimeResult ) );
     Log.i( "Anti-Pump", "pumpTime index == " + index );
    pumpTimeSpinner.setSelection( index + 5 );
} else {
    pumpTimeSpinner.setSelection( 0 );
}

08-16 14:24:31.151: I/Anti-Pump(3037): pumpCountResult==8
08-16 14:24:31.151: I/Anti-Pump(3037): pumpTimeResult ==34
08-16 14:24:31.151: I/Anti-Pump(3037): pumpTime index == 5
08-16 14:24:31.151: I/Anti-Pump(3037): ppumpDelayResultt==19

The spinner has values from 30-300, with "N/A" before it. So there are 271 entries.

Upvotes: 0

Views: 122

Answers (1)

Jeshurun
Jeshurun

Reputation: 23186

Have you tried:

yourSpinner.setSelection(2);

in your code?

Upvotes: 1

Related Questions