Android spinner get current selection so I know I am changing it

I have a spinner and I need to knows its current value, either text or position or both. I don’t know the starting value before the test is run and I must change they value. Let’s just say it is your default language. App starts up, loads your language from web (i.e. your last setting) and it is Chinese.

For my test I need the language to change. I am testing to see if after a user makes a change in the dialog that they are prompted with “You changed: X, Y, Z doe you want to Discard that change?”. I am doing this for every single control on the screen and have this working for text editors and switches. Since I don’t know what the old language is - that is not part of the test - I MUST change the language to a new value. I can not assume that “English” or “Spanish” is a new value nor can I assume “Chinese” was the original value.

I thought this might work but current_value is always ‘’ and not the current text shown in the spinner (code is Ruby)

def verify_spinner_change_prompts(profile_screen_object, section_name, spinner_id, value, alt_value)
  visit_screen_section_scroll_control(profile_screen_object, section_name)
  spinner_field = find_element(:id, spinner_id)
  current_value = spinner_field.text
  spinner_field.click
  if (value == current_value) 
    scroll_to_exact(alt_value).click
  else
    scroll_to_exact(value).click
  end  
  validate_prompt_for_changed    
end

As you can see I can pass in two different values to the method in case the first one is the current value. This will always allow me to select a new value (if I can get the original value that is)

How can I get the current value from the spinner?

I found a solution. I pass in a second ID which is the ID of the TextView owned by the spinner.

def verify_spinner_change_prompts(profile_screen_object, section_name, spinner_id, spinner_text_id, value, alt_value)
  visit_screen_section_scroll_control(profile_screen_object, section_name)
  spinner_field = find_element(:id, spinner_id)
  spinner_text_field = find_element(:id, spinner_text_id)
  current_value = spinner_text_field.text
  spinner_field.click
  if (value == current_value) 
    scroll_to_exact(alt_value).click
  else
    scroll_to_exact(value).click
  end  
  validate_prompt_for_changed    
end

That allows me to get to the current text. All the other code worked as expected using this minor change.