The following spinner is still clickable to show the list:
<Spinner
android:id="#+id/spinnerFoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="15dp"
android:gravity="center"
android:clickable="false"/>
Could anyone shed some light on this?
I know from my reading that one can disable a spinner by doing it in Java code (spinnerFoo.setEnabled(false). My question is about doing it in XML.
[EDIT]
The following is all the Java code using the spinner:
ArrayAdapter<Integer> adapterFoo = new ArrayAdapter<Integer>(this, R.layout.spinner_item, aiFoo);
spinnerFoo = (Spinner) findViewById(R.id.spinnerFoo );
spinnerFoo .setAdapter(adapterFoo );
spinnerFoo .setSelection(1);
Clickable is not going to stop the spinner from opening because it does not depend on click event.You have to use android:enabled="false"
EDIT
You can set this in the Java code itself, instead of in the XML, because the Spinner should implement setEnabled(boolean) from View
Add this android:enabled="false"
Write this in your xml
android:enabled="false"
Related
I'm trying to put a spinner on a layout for android app. Unlike other components, the spinner does not come with an option to give a hint. How can I do it?
This is my spinner:
<Spinner
android:id="#+id/spinner_gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/gender"
android:background="#android:color/white" />
When it's not selected I want to show a text like "Gender". When we select it i want that we can't select the option gender and that we only select Male or Female.
The options inside spinner are in an xml called where I keep the arrays.
Thanks.
Unfortunately Spinner don't have this feature built-in. Please check this post
This feature can be easily implemented through the library with so much customization:
https://github.com/Mobile-Innowise-Group/HintedSpinner
Usage of the library and with a lot of customized params:
<com.innowisegroup.hintedspinner.HintedSpinner
android:id="#+id/hintedSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
app:hintTextSize="24sp"
app:hintTextColor="#color/red"
app:hint="Custom hint"
app:withDivider="true"
app:dividerColor="#color/dark_green"
app:arrowDrawable="#drawable/example_arrow_4"
app:arrowTint="#color/colorAccent"
app:popupBackground="#color/light_blue"
app:items="#array/text" />
As you can see from the screenshot below, the first item in the listview isnt centered vertically. How can I center it?
Activity XML
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/button"
android:layout_alignParentTop="true" />
Code, I'm just populating the listview from books array...
List<String> books = new ArrayList<String>();
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(Main.this, android.R.layout.simple_list_item_1, books);
lvFirst.setAdapter(adapter1);
Try adding this line to your ListView XML:
android:gravity="center"
It should look like this:
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/button"
android:layout_alignParentTop="true"
android:gravity="center"/>
EDIT:
Sorry, now I understood your issue.
You're using "android.R.layout.simple_list_item_1" as your built in layout, but it won't work that way.
This is a duplicate of this question.
Just summing it up, you need to create your own layout to pass to the adapter. The answer is in the question link posted above.
Thank you for your time and answers, but I couldnt believe that that it was that bad of an implementation so I just listed some default layouts and this fixed my issue, so I want to write it here to help someone in the future.
adapter1 = new ArrayAdapter<String>(Main.this, android.R.layout.simple_selectable_list_item, books);
I just changed:
android.R.layout.simple_list_item_1
to:
android.R.layout.simple_selectable_list_item
I'm using Spinner in my android app, but I've a problem. It works fine, but its color is darker than they use to have, but I don't know why. Is not a problem with themes or styles, is more, I used Spinners recently for other project and It works perfectly. Did it happen to you? How did you solve it?
I don't use any custom component for this example, so I don't attach the code, but If you need it just ask for.
it may be because you passed different resource id to spinner arrayAdapter.. try passing android.R.layout.simple_spinner_item to your adapter
yourSpinnerArrayAdapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item, your_list);
hope this helps...:)
You can create a custom layout for spinner, it will be more customizable
custom_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:gravity="left"
android:textColor="#000000"
android:padding="10dip"
/>
And your spinner adapter
yourSpinnerArrayAdapter = new ArrayAdapter(this,R.layout.custom_spinner, your_list);
Can someone tell me how can I show suggestions on a "Multiline" MultiAutoCompleteTextView. I went to the API reference Here.
I tried that example and the Autocomplete worked just fine except when i go to the next line I do not see the suggestions any more.
I have an xml that definees my MultiAutoCompleteTextView like so:
<?xml version="1.0" encoding="utf-8"?>
<MultiAutoCompleteTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/html"
android:focusable="true"
android:gravity="top"
android:background="#null"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:singleLine="false"
android:completionThreshold="1"
android:textSize="14dp"
android:scrollHorizontally="true"
android:focusableInTouchMode="true" />
My code that does the suggestions is like so: (Got it from the reference)
MultiAutoCompleteTextView editor = (MultiAutoCompleteTextView) LayoutInflater.from(getApplicationContext()).inflate(R.layout.editor, null);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
editor.setAdapter(adapter);
editor.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
Since I set the singleLine to false on my MultiAutoCompleteTextView xml. The suggestions do not show when I press enter to go to the next line.
Can anyone help me on this. Is there a way i can override the suggestions panel to my liking? Also is there a way to position the panel?
android:inputType="textMultiLine"
"Normal text keyboard that allow users to input long strings of text that include line breaks (carriage returns)."
http://developer.android.com/guide/topics/ui/controls/text.html
I have a Spinner which displays single digit numbers (1-6).
When I test on a phone, it's virtually impossible to click on a number because they are so narrow (font size is 12sp) and the only area which appears to be clickable is the text itself.
Ideally I'd like the user to be able click on a greater width on the Spinner drop down than just the text. I've tried padding with spaces but these are suppressed, and I've tried using PaddingLeft/Right but again there's no difference.
Here is the Spinner
<Spinner
android:id="#+id/spinner_period1"
android:layout_toRightOf="#id/spinner_weekday1"
android:layout_below="#id/col1day"
android:layout_height="wrap_content"
android:prompt="#string/enterperiod"
android:layout_width="80dp"
android:entries="#array/periodlist"
android:layout_marginRight="340dp"
android:layout_marginBottom="20dip"
/>
Note that I also set the Spinner text attributes using:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textview"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="12sp"
android:textColor="#768766"
/>
Any ideas? Thanks in advance
Mark
Try making the TextView wider in the android:layout_width attribute.
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textview"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textSize="12sp"
android:textColor="#768766"
/>
That could possibly fix your issue or make it better at least.
Try setting your TextView layout width to some arbitrary value rather than "wrap_content". That should make the whole thing clickable, as opposed to just the wrapped content.
Just adding some padding to the spinner helped me fix this issue.
<Spinner
android:id="#+id/spinner"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:padding="25dp"
android:scrollbarSize="20dp" />
Way 1:
Display the spinner's options as a dropdown by using android:spinnerMode. Therefore have a look at the API (Android API Spinner). Or play around with android:dropDownWidth.
Way 2 (I used it in an APP but at the moment I have no access to the code):
Maybe you could set another layout while populating your spinner with text - instead of assigning the values in the XML.
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
It's copied from the following link Android Spinner. Maybe you could use one of the layout templates of android.R .