Code example for Spinner

Methods: getAdapter, setSelection

1
    public void testShouldStoreSelectedValueInChildJSONObject() throws JSONException { 
        field.setOptionStrings(new HashMap<String, List<String>>(){{put("en", Arrays.asList("one", "two", "three"));}});
        view.initialize(field, child); 
 
        Spinner spinner = view.getSpinner();
        String option1 = (String) spinner.getAdapter().getItem(1);
        spinner.setSelection(1);
 
        assertEquals(option1, child.get(field.getId()));
 
        String option2 = (String) spinner.getAdapter().getItem(2);
        spinner.setSelection(2);
        assertEquals(option2, child.get(field.getId()));
    } 
 
    @Test 
    public void testShouldSetTranslations() { 
        HashMap<String, List<String>> optionStringsHash = new HashMap<String, List<String>>();
        optionStringsHash.put("en", Arrays.asList("one", "two"));
        optionStringsHash.put("fr", Arrays.asList("oneInFrench", "twoInFrench"));
        field.setOptionStrings(optionStringsHash);