Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The text on my spinners is white, and I have no idea why.

enter image description here

This is my xml, nothing special

 <Spinner
     android:id="@+id/spinner_date"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="1" />

And my code

dateSpinner = (Spinner) findViewById(R.id.spinner_date);
selectedDate = calendar.getTime();
List<String> list = new ArrayList<String>();
list.add(formatter.format(selectedDate));
dateAdapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item, list);
dateSpinner.setAdapter(dateAdapter);

What could be the reason that my text is displayed in white?

EDIT: I've found the reason, I replaced the mContext parameter which was set in my onCreate.

mContext = getApplicationContext();

Now I use d

ateAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, list);

and it works.

question from:https://stackoverflow.com/questions/16354168/text-on-spinner-is-white-on-a-white-background

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
144 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have same problem and have found the answer. You dont use application context, instead, just use getActivity() (if you are in fragment) or this (if you are in activity), it will work

 dateAdapter = new ArrayAdapter<String>(**this**,
        android.R.layout.simple_spinner_item, list);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...