Search code examples
androidandroid-listfragment

Unable to change text color of ListFragment items


I have a ListFragment populated from a Cursor. I have the list background set to white, and for some reason the text is also set to white. I've tried changing the textColor attribute in the layout xml, but it doesn't seem to have any effect. Can someone point out what I'm missing? Thanks.

From the ListFragment:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String[] from = {DBConstants.COL_FAMILY_NAME};
    int[] to = {android.R.id.text1};

    getLoaderManager().initLoader(FAMILY_LOADER, null, this);
    adapter = new SimpleCursorAdapter(getActivity().getApplicationContext(), R.layout.simple_spinner_drop_down_view, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    setListAdapter(adapter);
}


@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    registerForContextMenu(getListView());

    getListView().setBackgroundResource(android.R.color.white);
    getListView().setCacheColorHint(android.R.color.transparent);
}

The list item layout:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/spinnerItemText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="15dip"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#000000" />

Solution

  • I suspect the text isn't white, it just isn't showing up because you're binding to the wrong TextView. I think you need to change this line:

    int[] to = {android.R.id.text1};
    

    to this:

    int[] to = {R.id.spinnerItemText};