Best way to show a loading/progress indicator?

ProgressDialog is deprecated from Android Oreo. Use ProgressBar instead ProgressDialog progress = new ProgressDialog(this); progress.setTitle(“Loading”); progress.setMessage(“Wait while loading…”); progress.setCancelable(false); // disable dismiss by tapping outside of the dialog progress.show(); // To dismiss the dialog progress.dismiss(); OR ProgressDialog.show(this, “Loading”, “Wait while loading…”); Read more here. By the way, Spinner has a different meaning in Android. (It’s … Read more

How to wrap lengthy text in a spinner? [duplicate]

Step 1. TextView with wrapped text The first thing to do is to to force simple TextView to wrap text. Its easy: <TextView android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:singleLine=”false” android:text=”very long text that will be wrapped to next line” /> Note the singleLine attribute here. Step 2. Custom layout Now we should somehow set singleLine attribute to false … Read more

Change text color of selected item in spinner

Define OnItemSelectedListener like this: private AdapterView.OnItemSelectedListener listener = new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(0x00000000); } @Override public void onNothingSelected(AdapterView<?> parent) { } }; and then Set OnItemSelectedListener to spinner like this: spinner.setOnItemSelectedListener(listener);

Android : Fill Spinner From Java Code Programmatically

// you need to have a list of data that you want the spinner to display List<String> spinnerArray = new ArrayList<String>(); spinnerArray.add(“item1”); spinnerArray.add(“item2”); ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, spinnerArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Spinner sItems = (Spinner) findViewById(R.id.spinner1); sItems.setAdapter(adapter); also to find out what is selected you could do something like this String selected = sItems.getSelectedItem().toString(); … Read more

How to set dropdown arrow in spinner?

Basically one needs to create a custom background for a spinner. It should be something like this: spinner_background.xml <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <layer-list> <item> <color android:color=”@android:color/white”/> </item> <item> <bitmap android:gravity=”center_vertical|right” android:src=”https://stackoverflow.com/questions/20422802/@drawable/ic_arrow_drop_down_black_24dp”/> </item> </layer-list> </item> </selector> Then create a custom style for your spinner, where you specify the above selector as background: <style name=”Widget.App.Spinner” parent=”@style/Widget.AppCompat.Spinner”> <item name=”overlapAnchor”>true</item> … Read more

How to limit the height of Spinner drop down view in Android

You can use Reflection. Spinner spinner = (Spinner) findViewById(R.id.spinner); try { Field popup = Spinner.class.getDeclaredField(“mPopup”); popup.setAccessible(true); // Get private mPopup member variable and try cast to ListPopupWindow android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner); // Set popupWindow height to 500px popupWindow.setHeight(500); } catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) { // silently fail… }

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