How to set Spinner Default by its Value instead of Position?

If you are setting the spinner values by ArrayList or Array you can assign the spinner’s selection by using the value’s index. String myString = “some value”; //the value you want the position for ArrayAdapter myAdapter = (ArrayAdapter) mySpinner.getAdapter(); //cast to an ArrayAdapter int spinnerPosition = myAdapter.getPosition(myString); //set the default according to the value spinner.setSelection(spinnerPosition); … Read more

Difference between getView & getDropDownView in SpinnerAdapter

If we look at the following code, we have name and value array in getView and getDropDownView. private void initView() { SpinnerDropDownAdapter sddadapter = new SpinnerDropDownAdapter(this); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, sddadapter.name); Spinner getViewSP = (Spinner) findViewById(R.id.getview_sp); getViewSP.setAdapter(adapter); Spinner getViewWDropDownSP = (Spinner) findViewById(R.id.getview_w_drop_down_sp); getViewWDropDownSP.setAdapter(sddadapter); } static class SpinnerDropDownAdapter extends BaseAdapter implements SpinnerAdapter { Context … Read more

Android Spinner with multiple choice

I have written custom implementation of MultiSpinner. It’s looking similar to normal spinner, but it has checkboxes instead of radiobuttons. Selected values are displayed on the spinner divided by comma. All values are checked by default. Try it: package cz.destil.settleup.gui; public class MultiSpinner extends Spinner implements OnMultiChoiceClickListener, OnCancelListener { private List<String> items; private boolean[] selected; … Read more

Spinner does not wrap text — is this an Android bug?

In holo theme spinner by default uses dropdown mode. And all moves with overriding default styles just move to switching spinner mode to dialog mode which succesfully wraps multiline text as in api 11. Instead you can create spinner with new Spinner(context, Spinner.MODE_DIALOG) or in xml: android:spinnerMode=”dialog”. But it’s not resolve the problem, because it’s … Read more

Change Spinner dropdown icon

Try applying following style to your spinner using style=”@style/SpinnerTheme” //Spinner Style: <style name=”SpinnerTheme” parent=”android:Widget.Spinner”> <item name=”android:background”>@drawable/bg_spinner</item> </style> //bg_spinner.xml Replace the arrow_down_gray with your arrow <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <layer-list> <item> <shape> <gradient android:angle=”90″ android:endColor=”#ffffff” android:startColor=”#ffffff” android:type=”linear” /> <stroke android:width=”0.33dp” android:color=”#0fb1fa” /> <corners android:radius=”0dp” /> <padding android:bottom=”3dp” android:left=”3dp” android:right=”3dp” android:top=”3dp” /> </shape> </item> <item … Read more

Change spinner background color but keep arrow

I did a little modification based on @Mansur Khan ‘s answer. We don’t have to add an ImageView in this case because the spinner already has a triangle arrow. So check the code below: <RelativeLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:padding=”8dp” android:background=”#FFFFFF”> <Spinner style=”@style/Widget.AppCompat.DropDownItem.Spinner” android:layout_width=”match_parent” android:layout_height=”70dp” android:id=”@+id/sign_up_country” /> </RelativeLayout> Here is the screenshot Before: After:

Change color of the drop down arrow of Spinner in XML

There are three ways to achieve that. 1. Through code: In your xml, make sure your spinner has an id. Let’s say we have a spinner with id “spinner”. In your code, add the following in your onCreate(): Spinner spinner = (Spinner) findViewById(R.id.spinner); spinner.getBackground().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP); where red is your defined color in colors.xml in the … Read more

How to add a Dropdown item on the action bar

First option: menu/options.xml: <item android:icon=”@drawable/ic_menu_sort” android:showAsAction=”ifRoom”> <menu> <item android:id=”@+id/menuSortNewest” android:title=”Sort by newest” /> <item android:id=”@+id/menuSortRating” android:title=”Sort by rating” /> </menu> </item> Second option: menu/options.xml: <menu xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:id=”@+id/menuSort” android:showAsAction=”ifRoom” android:actionLayout=”@layout/action_sort” /> </menu> layout/action_sort.xml: <Spinner xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@drawable/ic_menu_refresh” android:entries=”@array/order” /> Docs for menu resources – http://developer.android.com/guide/topics/resources/menu-resource.html

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)