filipebarretto filipebarretto - 1 month ago 9
Android Question

MultiAutoCompleteTextView list items not showing text

I am developing an Android application and I've never worked with MultiAutoCompleteTextView before.

In my layout.xml I've added:

<MultiAutoCompleteTextView
android:id="@+id/autocomplete_subtest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:ems="10"
android:text="" />


And in my DialogFragment:

try {
subtestAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(R.id.autocomplete_subtest);
ArrayAdapter<String> subtestAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, subtests);

subtestAutoCompleteTextView.setAdapter(subtestAdapter);
subtestAutoCompleteTextView.setThreshold(1);
subtestAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
} catch (Exception e) {
e.printStackTrace();
}


The items, however, appear with a transparent text:

enter image description here

If I click on the list item, with the empty text, it completes my MultiAutoCompleteTextView with an expected option.

Any idea why the text does not show on the item?

Answer

You should change the text color of list item. It`s may be white so change to black.

EDIT 1

Just to explain how to solve this, I followed this link: How to change text color of simple list item

Basically, create a custom layout.xml file with the TextView:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tv"
    android:textColor="@color/font_content"
    android:padding="5sp"
    android:layout_width="fill_parent"
    android:background="@drawable/rectgrad"
    android:singleLine="true"
    android:gravity="center"
    android:layout_height="fill_parent"/>

And in my code I changed:

    ArrayAdapter<String> subtestAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.my_layout_file, subtests);
Comments