Expandable Android list Black background when scrolling

I am struggling with ListView extension in Android. I am using the code provided in the apis demo, but I do not know how to solve my problem.

I have a white background on a white background, but when I scroll through the list it turns black.

I don't want this effect ... is there a way to change it? is there a way to customize the list using this code? I'm looking for something like this ... Hope you can help me! Thank:)

package com.example.android.apis.view;

import android.R;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.SimpleExpandableListAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Demonstrates expandable lists backed by a Simple Map-based adapter
 */
public class ExpandableList3 extends ExpandableListActivity {
    private static final String NAME = "NAME";
    private static final String IS_EVEN = "IS_EVEN";

    private ExpandableListAdapter mAdapter;

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

        List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
        List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
        for (int i = 0; i < 20; i++) {
            Map<String, String> curGroupMap = new HashMap<String, String>();
            groupData.add(curGroupMap);
            curGroupMap.put(NAME, "Group " + i);
            curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");

            List<Map<String, String>> children = new ArrayList<Map<String, String>>();
            for (int j = 0; j < 15; j++) {
                Map<String, String> curChildMap = new HashMap<String, String>();
                children.add(curChildMap);
                curChildMap.put(NAME, "Child " + j);
                curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
            }
            childData.add(children);
        }

        // Set up our adapter

        mAdapter = new SimpleExpandableListAdapter(
                this,
                groupData,
                android.R.layout.simple_expandable_list_item_1,
                new String[] { NAME, IS_EVEN },
                new int[] { android.R.id.text1, android.R.id.text2 },
                childData,
                R.layout.simple_expandable_list_item_3,
                new String[] { NAME, IS_EVEN },
                new int[] { android.R.id.text1, android.R.id.text2 }
                );

        setListAdapter(mAdapter);
    }

}

      

+2


source to share


6 answers


Add to the list in the xml file:

android:cacheColorHint="#00000000"



or in your Java code:

getListView().setCacheColorHint(0);

+7


source


add android:cacheColorHint="#00000000"

to ListView

Example



<ListView
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:id="@+id/list"
   android:cacheColorHint="#00000000" />

      

+5


source


Write this in your xml, you will get the answer

Android: scrollingCache = "false"

+2


source


Follow the instructions on this link:

Android Ressources for Android: Browsing History

In short: ... To fix this problem, all you have to do is either disable cache hint optimization if you are using a non-solid background color, or set the hint to the appropriate solid color value. You can do it from code (see SetCacheColorHint (int)) or preferably from XML using the android: cacheColorHint attribute. To disable optimization, just use transparent color # 00000000. The following screenshot shows a list with android: cacheColorHint = "# 00000000" set in the XML layout file ...

+1


source


I would like to point out that there is a more elegant way of expression #00000000

, just use: @android/color/transparent

. It's easier to understand if you come back to this code after a while (yes, I know it's just an ARGB number anyway;)).

0


source


Just set the color of the list using the following methods:

android:cacheColorHint="#000000"

      

or in your Java code:

listView.setCacheColorHint(0);

      

0


source







All Articles