Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spinner does not show selected value

I have implemented the spinner by populating the array list through database.I can get and show the array list in my spinner array adapter but if I select the item in spinner it does not shown in spinner?What I had mistake here?

Here is my code,

 Spinner spinner1 = (Spinner) findViewById(R.id.prospin);
     ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, providerlist);

  adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);

I get the selected item string by using this,

Spinner provid = (Spinner)findViewById(R.id.prospin);
String provider =provid.getSelectedItem().toString();

Can anyone help me out pls!!!

like image 629
Jolly Avatar asked Dec 03 '13 14:12

Jolly


3 Answers

This answer may be a little stupid but try it. It worked for me.

  1. Check the background color of your spinner!
  2. And if it`s white change it
  3. Enjoy it!
like image 76
Catluc Avatar answered Oct 20 '22 20:10

Catluc


I got same problem and solved by adding notifyDataSetChanged() after binding data in Spinner.

First of all I have bind adapter with Blank ArrayList then getting List of Items from Server and added to that List but forgot to notifyDataSetChanged() after updated List.

just add adapter.notifyDataSetChanged(); after updating list.

Hope it will helpful.

like image 20
Pratik Butani Avatar answered Oct 20 '22 20:10

Pratik Butani


Problem:

Spinner displays neither the default nor selected item value. But drop-down menu items are show when selected.

Cause:

Background and text color both being white!!!

Solutions:

xml(Preferable):

Write a custom layout for a spiner item and use it instead of the default,android.R.layout.simple_spinner_item.

How to change spinner text size and text color?

Code(Less reliable):

your_spinner_instance.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
    public void onItemSelected(AdapterView<?> parent, View view, int pos,
                               long id) {
        ((TextView) view).setTextColor(Color.RED);
    }
    public void onNothingSelected(AdapterView<?> parent) {
    }

});

Android needs some major update or maybe dart and flutter should take over...

Thanks Catluc

like image 12
TastyCatFood Avatar answered Oct 20 '22 19:10

TastyCatFood