Android Spinner with no selected text - arrow only - android

I would like to create a spinner which only displays the drop-down arrow and not the selected value and is only the width of the arrow. You can see various examples of this in Android itself e.g. Settings->Display->Brightness (Edit: a commenter has pointed out that this is a DialogPreference, but I would like a similar effect using a spinner).
I have attached to the setOnItemSelectedListener event and set the selected text to null, but this does not decrease the width of the spinner and you can can briefly see the selected text flicker before it is set to null.
How can I do this with the spinner? Is the spinner the correct control to be using in the first place?
Thanks.

Related

Android: drop down input with left and right icons

I have an android application with a drop down list which have left and right icon, I try to use spinner with left and right drawable, but does not work, what I need is look like below where user can only enter (select) from the list, which mean autocomplete text is not useful, also dropped list does not contain image, How can I achieve that?
So after better understanding your idea, this is the steps you need.
create a custom adapter (this should take the list of string you want to display and the list of icons )
list item is one edit text like
<EditText
...
android:drawableLeft="#drawable/my_icon" />
create your spinner and set the adapter
Spinner sp = findViewById(R.id.spinner);
sp.setAdapter(your custom adapter)
add the item selected listener and you are done.
More info on adapters
You need to use a custom spinner With Image And Text and a card view back ground for spinner. check this link how to add drop-down menu spinner. https://stackoverflow.com/a/24422359/2546742

Disable spinner from moving to last selected item on dropdown

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?

Spinner dialog click outside text

I'm using a custom Spinner in a dialog mode. Each item element has one text. The text in each item line is very short, eg. "A", "AB", "BC", etc. In order to select a line I have to click exactly the text (the background is than changing into blue and the item is selected correctly). When I click outside this short text but in the item line it is not selected. Is it possible to force the selection when I click the item line not exactly the item text?
If you are using a custom spinner then you should be able to access the textview element in the xml for the class.
In this xml, the textview element try changing the property
Android:layout_width="match_parent"
You may also use the padding and margin to adjust the same.

Show only text on spinner without dropdown

i want to show a image and text on spinner & dont want to see the dropdown, look at the image shown below, like this need to have text and image. i.e image at left side and text at right end. Also we require selection happening on the spinner.
Eg: If i click on setDate the calender should come and chosen date should sit on spinner.
just add following line for disabling spinner:
spinner.setClickable(false);
and for selecting your row you can use following code:
spinner.setSelection(spinnerPosition);
that spinnerPosition is that position that you want.

Spinner items selection radio missing

When my items contains English and/or numeric signs, it shows the radio selection near the item, but when it doesn't contains any English and/or numeric signs (contains only Hebrew in my example) it does not show the radio selection near the item.
For the adapters (array adapter) creation i used the layout "android.R.layout.simple_spinner_item"
And before setting the Spinner adapter I did
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
The solution I found for now, is set the layout to "simple_dropdown_item_1line"; this solves the problem by not showing the radio button.
Any ideas on how to get the radio button visible always?
correction - the solution does not work. for few of my spinners it shows a white text on a white background.
Hi the below code works for me in hebrew
For the Adapter use android.R.layout.simple_spinner_item
and myAdapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
Regards,
Yaron
Any ideas on how to get the radio button visible always?
Use an appropriate layout for the drop-down view resource. android.R.layout.simple_spinner_dropdown_item should always work. If you create your own layout, and it does not work, identify where you changed things from android.R.layout.simple_spinner_dropdown_item that would affect matters (e.g., text color, background color).

Categories

Resources