How to add floating label on Spinner

I want the text size, font and colour to match that of the TextInputLayout‘s floating label. This can be achieved easily without any external libraries. After trying to hack the TextInputLayout and even making my own custom view, I realized that using a simple TextView takes much less code and it’s probably more efficient. The … Read more

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 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

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 customize a Spinner in Android

Create a custom adapter with a custom layout for your spinner. Spinner spinner = (Spinner) findViewById(R.id.pioedittxt5); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.travelreasons, R.layout.simple_spinner_item); adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); R.layout.simple_spinner_item <TextView xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@android:id/text1″ style=”@style/spinnerItemStyle” android:maxLines=”1″ android:layout_width=”match_parent” android:layout_height=”wrap_content” android:ellipsize=”marquee” /> R.layout.simple_spinner_dropdown_item <CheckedTextView xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@android:id/text1″ style=”@style/spinnerDropDownItemStyle” android:maxLines=”1″ android:layout_width=”match_parent” android:layout_height=”?android:attr/dropdownListPreferredItemHeight” android:ellipsize=”marquee” /> In styles add your custom dimensions and height as per your … Read more

Android Spinner : Avoid onItemSelected calls during initialization

spinner.setOnItemSelectedListener(this); // Will call onItemSelected() Listener. So first time handle this with any Integer value Example: Initially Take int check = 0; public void onItemSelected(AdapterView<?> parent, View arg1, int pos,long id) { if(++check > 1) { TextView textView = (TextView) findViewById(R.id.textView1); String str = (String) parent.getItemAtPosition(pos); textView.setText(str); } } You can do it with boolean … Read more

How to create a drop-down list?

simple / elegant / how I do it: Preview: XML: <Spinner android:id=”@+id/spinner1″ android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”@android:drawable/btn_dropdown” android:spinnerMode=”dropdown”/> spinnerMode set to dropdown is androids way to make a dropdown. (https://developer.android.com/reference/android/widget/Spinner#attr_android:spinnerMode) Java: //get the spinner from the xml. Spinner dropdown = findViewById(R.id.spinner1); //create a list of items for the spinner. String[] items = new String[]{“1”, “2”, “three”}; //create … Read more

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