Multi selection spinner in android without AlertDialog

multi select spinner : 1- create a spinner in your own xml ,like this <Spinner android:id=”@+id/mySpinner” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_alignParentRight=”true” android:layout_marginTop=”1dp”/> 2-create a custom dapter for spinner like this : public class AdapterTagSpinnerItem extends ArrayAdapter<TagListSimpleSearch> { private LayoutInflater mInflater; private List<TagListSimpleSearch> listState; public Spinner mySpinner = null; public AdapterTagSpinnerItem(Context context, int resource, List<TagListSimpleSearch> objects, Spinner mySpinner) … Read more

How to set font custom font to Spinner text programmatically?

This is what worked for me (using ideas both from CommonsWare’s and gsanllorente’s answers): private static class MySpinnerAdapter extends ArrayAdapter<String> { // Initialise custom font, for example: Typeface font = Typeface.createFromAsset(getContext().getAssets(), “fonts/Blambot.otf”); // (In reality I used a manager which caches the Typeface objects) // Typeface font = FontManager.getInstance().getFont(getContext(), BLAMBOT); private MySpinnerAdapter(Context context, int resource, … 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

Android: Where is the Spinner widget’s text color attribute hiding?

I think it’s probably this bit in styles.xml <style name=”Widget.TextView.SpinnerItem”> <item name=”android:textAppearance”>@style/TextAppearance.Widget.TextView.SpinnerItem</item> </style> <style name=”Widget.DropDownItem.Spinner”> <item name=”android:checkMark”>?android:attr/listChoiceIndicatorSingle</item> </style> -= EDIT =- Here’s the result: and here’s how it’s done: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <style name=”MooTheme” parent=”android:Theme”> <item name=”android:spinnerItemStyle”>@style/MooSpinnerItem</item> </style> <style name=”MooSpinnerItem” parent=”android:Widget.TextView.SpinnerItem”> <item name=”android:textAppearance”>@style/MooTextAppearanceSpinnerItem</item> </style> <style name=”MooTextAppearanceSpinnerItem” parent=”android:TextAppearance.Widget.TextView.SpinnerItem”> <item name=”android:textColor”>#F00</item> </style> </resources> Then just add … Read more

Android: Create spinner programmatically from array

ArrayAdapter<String> should work. i.e.: Spinner spinner = new Spinner(this); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, spinnerArray); //selected item will look like a spinner set from XML spinnerArrayAdapter.setDropDownViewResource(android.R.layout .simple_spinner_dropdown_item); spinner.setAdapter(spinnerArrayAdapter);

How to set selected item of Spinner by value, not by position?

Suppose your Spinner is named mSpinner, and it contains as one of its choices: “some value”. To find and compare the position of “some value” in the Spinner use this: String compareValue = “some value”; ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.select_state, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinner.setAdapter(adapter); if (compareValue != null) { int spinnerPosition = adapter.getPosition(compareValue); mSpinner.setSelection(spinnerPosition); }

How to keep onItemSelected from firing off on a newly instantiated Spinner?

The use of Runnables is completely incorrect. Use setSelection(position, false); in the initial selection before setOnItemSelectedListener(listener) This way you set your selection with no animation which causes the on item selected listener to be called. But the listener is null so nothing is run. Then your listener is assigned. So follow this exact sequence: Spinner … Read more