I have a spinner defined as: <Spinner android:id="@+id/spinner_temperature" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/temperature_units" android:prompt="@string/prompt_temperature_units" />
In strings.xml I have <string-array name="temperature_units"> <item><sup>o</sup>C</item> <item><sup>o</sup>F</item> <item><sup>o</sup>K</item> </string-array> I want to set the index of the spinner by searching for one of the string values in the array temperature_units. When I look at the ArrayAdapter in the debugger, it says that the array has three elements: oF, oC, and oK. I tried this code: s = (Spinner) v.findViewById(R.id.spinner_temperature); s.setSelection(((ArrayAdapter<String>)s.getAdapter()).getPosition(data[choice][RocketModelsData.TEMPERATURE_UNITS])); where data[choice][RocketModelsData.TEMPERATURE_UNITS] returns a string contained in the array. but the spinner is not set to the expected value.. I broke down the statements into pieces, and tried to search on permutations of the strings in the array using this: s = (Spinner) v.findViewById(R.id.spinner_temperature); ArrayAdapter<String> sAdapter = (ArrayAdapter<String>) s.getAdapter(); int g0 = sAdapter.getPosition("F"); int g1 = sAdapter.getPosition("oF"); int g2 = sAdapter.getPosition("<sup>o</sup>F"); All three values, g0, g1, and g2 are -1, so the search failed. If I remove the superscript formatting from the array, the search works just fine for F, C, and K or oF, oC, and oK. Any suggestions on how to set the value of the spinner index by searching the strings in the spinner array? My layout is cramped, so I can't change the array elements, for example, to "degrees C"; ie removing the superscript formatting. Thanks, Mark P.S. Is there a way to read the array from the strings.xml file, and then make a shadow array that would have the <sup>o</sup>F strings? I could get the index from searching that array. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en