Put ENUM values to android spinner?

Similar to another answer, but you can use an ArrayAdapter to populate based on an Enum class. I would recommend overriding toString in the Enum class to make the values populated in the spinner more user friendly. In the activity: Spinner mySpinner = (Spinner) findViewById(R.id.mySpinnerId); mySpinner.setAdapter(new ArrayAdapter<MyEnum>(this, android.R.layout.simple_spinner_item, MyEnum.values())); Your enum class: public enum MyEnum{ … Read more

How to disable onItemSelectedListener to be invoked when setting selected item by code

A cleaner solution, in my opinion, to differentiate between programmatic and user-initiated changes is the following: Create your listener for the spinner as both an OnTouchListener and OnItemSelectedListener public class SpinnerInteractionListener implements AdapterView.OnItemSelectedListener, View.OnTouchListener { boolean userSelect = false; @Override public boolean onTouch(View v, MotionEvent event) { userSelect = true; return false; } @Override public … Read more

Add a spinner when Mat-table is loading?

table.component.html <table mat-table [dataSource]=”dataSource” class=”mat-elevation-z8″> <!– table here …–> <tr mat-header-row *matHeaderRowDef=”displayedColumns”></tr> <tr mat-row *matRowDef=”let row; columns: displayedColumns;”></tr> </table> <div *ngIf=”isLoading” style=”display: flex; justify-content: center; align-items: center; background: white;”> <mat-progress-spinner color=”primary” mode=”indeterminate”> </mat-progress-spinner> </div> table.component.ts isLoading = true; dataSource = null; ngOnInit() { this.annuairesService.getMedecins() subscribe( data => { this.isLoading = false; this.dataSource = data }, … Read more

Setting a spinner onClickListener() in Android

Here is a working solution: Instead of setting the spinner’s OnClickListener, we are setting OnTouchListener and OnKeyListener. spinner.setOnTouchListener(Spinner_OnTouch); spinner.setOnKeyListener(Spinner_OnKey); and the listeners: private View.OnTouchListener Spinner_OnTouch = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { doWhatYouWantHere(); } return true; } }; private static View.OnKeyListener Spinner_OnKey = new View.OnKeyListener() { … Read more

How to create android spinner without down triangle on the right side of the widget

This is quite an old question, but I think still relevant, so here’s my answer: Simplest Method lencinhaus answer is correct. It works, but it can be done in an even simpler way: Just add another background to it. The example below uses the standard Button background for a more homogeneous look-and-feel: <Spinner android:id=”@+id/my_spinner” android:layout_width=”wrap_content” … Read more

How to hide one item in an Android Spinner

To hide an arbitrary item or more than one item I think that you can implement your own adapter and set the index (or array list of indexes) that you want to hide. public class CustomAdapter extends ArrayAdapter<String> { private int hidingItemIndex; public CustomAdapter(Context context, int textViewResourceId, String[] objects, int hidingItemIndex) { super(context, textViewResourceId, objects); … Read more

How can an error message be set for the Spinner in Android?

There are a few solutions in this thread Creating a setError() for the Spinner: The EdmundYeung99‘s one works for me, either you are using your own adapter or not. Just put the following code in your validate function: TextView errorText = (TextView)mySpinner.getSelectedView(); errorText.setError(“”); errorText.setTextColor(Color.RED);//just to highlight that this is an error errorText.setText(“my actual error text”);//changes … Read more

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