* displayed instead of the first choice in the Adapter. * Decorator Adapter to allow a Spinner to show a 'Nothing Selected.' initially NothingSelectedSpinnerAdapter.java import class MainActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) public void onItemSelected(AdapterView<>.R.ntact_spinner_nothing_selected_dropdown, // OptionalĬontact_spinner_row_nothing_selected.xml Usage in above example Spinner spinner = (Spinner) findViewById(R.id.spinner) ĪrrayAdapter adapter = ArrayAdapter.createFromResource(this, R.anets_array, android.R.layout.simple_spinner_item) ĪtDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) Or with a prompt and something dynamic (could have had no prompt also): Using a standard prompt (notice that nothing is selected): You define a layout to 'look' like a prompt, for example, grayed out. If an image is uploaded, it will negate the background color and shape. The Dropdown doesn't normally show the prompt) The Listpicker is a popular choice for drop down menus with more than 5 choices. (Note: Some themes show a DropDown for a Spinner instead of a dialog. This allows you to use a standard prompt or define your own 'nothing selected' as the first row, or both, or none. (So you have to use the setTag or something else to ensure your convertView is correct.) Spinner does not support multiple view types There is an Android bug that makes this a little tougher to re-use views. (Swap cursor on the wrapped cursorAdapter of course.) Here is a working example tested for Android 2.3, and 4.0 (it uses nothing in the compatibility library, so it should be fine for awhile) Since it's a decorator, it should be easy to retrofit existing code and it works fine with CursorLoaders also. What you can do is decorate your SpinnerAdapter with one that presents a 'Select Option.' View initially for the Spinner to display with nothing selected. Using these i am not able to change the text color of selecetd item… I am able to change the background color of the selected item, the color of the dropdown item etc, but not the text color of selected item… how can I do that? How can I change the font color of the selected item in a spinner?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |