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.
Related
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
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.
In following list, when I click any item which has width equal to 2 lines (in below eg, CNX SMALLCAP), item gets highlighted appropriately.
Problem comes when I click any item which has width equal to 1 line (in below eg, ICICI BANK), then along with the clicked item half of the above and below item is also getting highlighted.
Highlighting is always using width=2 lines.
What can be done to remove this?
I tried using clearFocus() and clearAnimation() inside onListItemClick() , but no luck.
ANY HELP WILL BE LIFE-SAVER !!!
Since you have two lines, focusing both the lines when you have some content makes sense. Hence make the line which you are not using invisible or gone. You can also create separate custom adapter for your listview with single line.
I think you set the selected color on the ListView not into the ListView item i.e. TextView which you have display as item. You can either set selected color on TextView or just set the textview background color as #00000000
<TextView android:background="#00000000" />
using this you define the transparency of the textview color with this
I have a listview with a textview as each item. I want to change the textcolor of the selected item. For this use the onItemSelected method to make the changes. Say first I select the 1st row, the first row's textcolor changes. Now when I select the 2nd row, its text color also changes, but I want the 1st row's color to change back to its default color. How do I do that, since in the onItemSelected I only get the refernce of the currently selected item and not the last selected. Is there any way other than holding a reference to the last selected view.
When first item is selected store its position in instance variable of your activity, lets name it currentlySelected. Then combine with this Android: Access child views from a ListView
in order to get the view at position currentlySelected and change it's textcolor.
Instead of doing it in Java, you can let android handles it in the xml file. See Color State List Resource.
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.