21

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?

David Homes
  • 2,725
  • 8
  • 33
  • 53
  • I have the same problem -- it's also the text in the field itself, but I can fix that by setting android:textColor – Shawn Lauzon Aug 24 '11 at 17:12
  • 4
    Had the same problem, too. Looks like the problem is in the XML file that defines a line. I used the built-in android.R.layout.simple_list_item_1, but it was white-on-white. When I changed to android.R.layout.simple_dropdown_item_1line I could see the text. – SMBiggs Sep 03 '11 at 22:18
  • I myself just created my own simple_dropdown_item_1line - like resource and used it in my code. The text is black now :) – Yar Jan 28 '12 at 10:34

5 Answers5

21

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

androabhay
  • 655
  • 6
  • 13
  • 3
    Legend. Thanks so much for sharing that bit of info. You've saved me a LOT of time! – Eamorr Jul 26 '12 at 21:03
  • i have this bug right now on android.R.layout.select_dialog_item and *this* only for one autocompletetextview of the 2 I have. I just found the differentiating factor : this versus context. – Poutrathor Dec 19 '14 at 16:47
  • I can see text now but color is very very light. – Francis Aug 14 '15 at 19:26
3

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.

Poutrathor
  • 1,990
  • 2
  • 20
  • 44
1

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.

amol khedkar
  • 141
  • 1
  • 3
1

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?

Maximus
  • 8,351
  • 3
  • 29
  • 37
  • no, when i highlight on emulator (goes to orange bg / white text) every string is there and matches (that's why i meant by the AutoCompleteTextView working), so empty strings isn't it. Also, I don't see any theme in the AndroidManifest.xml. I looked at those before posting. I also tried applying – David Homes Apr 19 '11 at 05:44
  • Just started a new project and did EXACTLY what I did on the previous one. Now it's showing up. Maybe a bug on Eclipse? – David Homes Apr 19 '11 at 11:24
  • Maybe... on the original, did you try to use Project/Clean? I've certainly had to to that once or twice with odd situations... – Maximus Apr 19 '11 at 16:37
  • tried EVERYTHING under the sun. Project/Clean. Start a new project importing the previous one. NADA. – David Homes Apr 20 '11 at 04:04
  • but creating a new project with the exact same code did it (yes, turned off auto-compile, Cleaned project, deleted the content of gen folder, all that). I did read it online (lost URL) of someone else having the problem. – David Homes Apr 20 '11 at 04:06
  • AutoCompleteTextView with edittext? please, can you read again this post ? –  Nov 13 '15 at 09:52
0

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 );
Vijay
  • 2,021
  • 4
  • 24
  • 33