void loadFruitSpinner(Context context, Spinner spinner, final String strCurrentFruit) { ArrayList<String> list = new ArrayList<String>(Arrays.asList("apple", "banana", "pear")); int selected = -1; for (int i = 0; i < list.size(); i++) { if (list.get(i).equalsIgnoreCase(strCurrentFruit))) selected = i; } ArrayAdapter<String> adapter = new ArrayAdapter<String> (context, android.R.layout.simple_spinner_item, list); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setSelection(selected); }
Programming Tips - Android: How do I load a Spinner with a finite set of choices?
Date: 2017feb9
OS: Android
Language: Java
Q. Android: How do I load a Spinner with a finite set of choices?
A. Hear an example that lets the user pick a kind of fruit.