I have spinner with items created in getDropDownView() method. After the spinner is created I don't know why it scrolls to the last item in spinner (spinner is larger than whole screen view).
What I have now what scrolls to the bottom:
spinner.adapter = adapter
spinner.setSelection(adapter.count)
spinner.prompt = "my hint"
spinner.setSelection(-1) does not satisfy me cause it makes 1st item selected - then hint is invisible.
Question is how to scroll to the top of spinner items without selecting item? ScrollY, ScrollTo does not work here.
Greetings
From the question above I understand that you want to show hint when nothing is selected from spinner list.
Add hint at position zero of your list, i.e.
list.add("my hint");
list.add("option 1");
list.add("option 2");
.
.
list.add("option n");
And when user selects item from spinner list check that hint is not selected, i.e.
if (selectedPosition != 0)
Toast.makeToast(context, list.get(selectedPosition), Toast.TOAST_LONG).show();
Can I know why you are using spinner.setSelection(adapter.count) ?
Just remove -> spinner.setSelection(adapter.count)
or simply try with spinner.setSelection(0)
It will be selected in top of spinner items.
Related
I have a spinner I want to add two columns of checkboxes in the drop down of spinner.
I have tried this solution android spinner dropdown checkbox
but this does not let me show a hint "Please Select..." when no item is selected.
Here is what I want.
https://drive.google.com/open?id=11cr0iPgs9vwULeGeTAtllFR-3KW-6YvM
Unfortunately, standard spinner doesn't allow to show 'nothing selected' state after adapter is set. As soon as you set adapter first element become selected.
You should create custrom spinner for "nothing selected" position. See here http://stackoverflow.com/a/12221309
Seems, you should join solution from this link with link from your question
Is there a way to scroll spinner's dropdown list to top so first item is visible regardless which item is currently selected?
Obviously I need only to make vistible the item in the list without any selection.
ListView has smoothScrollToPosition() method to display a specific item in the list but spinner seems not to have a similar behavior.
I have a spinner where I am adding hint at the bottom(not adding to top as getSelectedItemPosition will consider the hint as well) using arrayadapter hiding it from showing on dropdown options. The problem I am facing is, if I make the hint to show for the first time by using setSelection, then drop will directly go to bottom of the list(though hint won't show). Is there way that the dropdown will always show the top item on dropdown list irrespective of what item I select previously?
I have a ListView, with different custom rows.
The last row contains a TextView and a Spinner. The Spinner works ok (when clicked the dropdown list is shown, when I choose an option it appears in the Spinner's prompt), but when I scroll up the list, the Spinner changes its value to the value in the first position (ie the string at position 0).
Why is this happening? And what can I do to stop this?
it will its the property create custonbaseadapter set getview and newview method
Advance List
Custom Apdapter
See this
I try to make a spinner which on its first use shows a text like "please select..." in its collapsed state and when it shows the dropdown state, it shows all the items, but nothing is selected.
I tried different approaches:
use a list with an extra "please select..." item and try to remove it from the list on first dropdown (the problem is there is no notification when the spinner drops down for the first time)
try to hide the first item in the dropdown view by overriding getDropDownView. But when I set the height of the view at position 0 to 0 pixel, the spinner leaves some extra space at the end of its view, it looks like the size of the view is calculated before getDropDownView is called.
Any other ideas? Thank You!