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!
Related
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.
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?
There is custom view and a ListView, both are coupled as such if one changes its state other must change. I am able to control custom view if one item of ListView is selected.
If a item is selected in custom view, corresponding item in List view should become visible and text in it must be hilighted.
I tried
listView.smoothScrollToPosition(clueIndex);
no scrolling happens on execution of this line.
Second question -
How can I get access to TextView in a particular adaptor postion and change its text color outside OnItemLongClickListener() ?
Issue resolved, due to error clueIndex was always -1.
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
In Android, I want to present the user with a list. When an item on the list is selected some action is performed, and this list item is no longer selectable. It is also 'grayed out' or the like to indicate that it cannot be selected the next time the list is displayed. I have seen the isSelectable() override in Adapter, but I believe this causes the item to be treated as a separator, which causes visual problems. And I have not found a way to 'gray out' an item. Any ideas? Thanks...
As far as graying out an item. I'm not sure if this is the best way, but it's what I do:
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
I'm basically making the item transparent and then setting the background color to gray. If you're reusing your list items you should also change them back to their original state if the condition is not met, i.e.:
view.setAlpha(255);
view.setBackgroundColor(Color.WHITE);
that is, if your original state was no transparency and the background color was white.
You need the view to be disabled. If you are creating the views just call .setDisabled(boolean) on the top view. Setting the list item to be disabled doesn't work very well in my experience.
Here is the solution I am using. I set up an OnItemClickListener for my ListView. When an item in the list is clicked, I take the passed in View and call setEnabled(false) on it. This will gray out the item. However, subsequent clicks on this item will still call the onItemClick method. So, you will need to check on each click if the item is enabled/disabled and act accordingly.