开发者

android AutoCompleteTextView white on white Dropdown list

breaking my head here, i have searched onlin开发者_Python百科e for quite a bit and it seems this was a bug on android before but have not found a solution yet.

I have a AutoCompleteTextView:

autodesignations = (AutoCompleteTextView) findViewById(R.id.main_autocomp);

adapterShapesAuto = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, shapes);

autodesignations.setAdapter(adapterShapes);

the widget works, but the dropdown text is always white text on white background.

I have tried setting the resource for the adapter to several combinations of android's built-in layouts & also my own.

Even pointing it to a TextView resource being also use for a Spinner (which works as expected, black text on white background), but have found no way of making this work, keep getting the same results

Any help?


I had this issue . Fixed it using android.R.layout.select_dialog_item for layout.


So here is the answer for my issue.

As often, this and a context reference are not exactly the same. Maybe because the context reference might be passed down across some activities, whatever.

So I changed that line (which is included inside a onClickListener) where 'context' is retrieved during onCreate() by getApplicationContext();

adapterListModele = new ArrayAdapter<String>(context, android.R.layout.select_dialog_item, listModeleNom);

into the following line where I used a this from my class :

adapterListModele = new ArrayAdapter<String>(AncestorVehicule.this, android.R.layout.select_dialog_item, listModeleNom);

And it works ! No more white font.

I tested it outside the onclicklistener callback and noticed 2 things :

  • using same 'context' variable did make the drop down to be displayed in white
  • sticking to 'this' avoids the issue.

Hope it helps someone else.


Very odd... I have AutoCompleteTextView's that work just fine. I found the size of the drop down entries was much too large so I ended up setting my own resource layout file. Stupid question... did you set the textColor in your xml?

Here's one I use...

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="6dp"
    android:textColor="#000000"
    android:ellipsize="marquee" />

Do you have some type of theme applied perhaps?

Also... perhaps the text isn't white, but instead you accidentally have empty strings?


I tried setting up the theme before setcontext, tried different resources parameter in arrayAdapter and tried different theme ,but nothing helped.

Then I changed the context from 'this' to 'getApplicationContext' but the problem was persistent.

Finally I changed the context parameter to "getBaseContext()" and the problem was solved.


Here is your answer

 SimpleCursorAdapter ad = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, null,
                new String[] { "item_Name" }, new int[] {android.R.id.text1} , 2 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜