Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android AutoCompleteTextView white on white Dropdown list

Tags:

breaking my head here, i have searched online 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?

like image 256
David Homes Avatar asked Apr 19 '11 00:04

David Homes


2 Answers

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

like image 160
androabhay Avatar answered Oct 12 '22 18:10

androabhay


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.

like image 31
Poutrathor Avatar answered Oct 12 '22 19:10

Poutrathor