Expandable List Android Black background while scrolling
I'm struggling with the ExpandableList View in Android. I'm using the code provided in the apis demo but I don't know how to solve my problem.
I got a white background on my view but when I'm scrolling the list it turns black..why?
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 could help me! Thank you :)
package com.example.android.apis.view;
import android.R;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.SimpleE开发者_StackOverflowxpandableListAdapter;
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);
}
}
Add to your listview in the xml file:
android:cacheColorHint="#00000000"
or in your Java code:
getListView().setCacheColorHint(0);
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" />
Write this one in your xml you will get the answer
android:scrollingCache="false"
Follow the instructions on this link:
Android Developer Ressources: Listview Backgrounds
In short: ...To fix this issue, all you have to do is either disable the cache color hint optimization, if you use a non-solid color background, or set the hint to the appropriate solid color value. You can do this from code (see setCacheColorHint(int)) or preferably from XML, by using the android:cacheColorHint attribute. To disable the optimization, simply use the transparent color #00000000. The following screenshot shows a list with android:cacheColorHint="#00000000" set in the XML layout file ...
I'd just like to point out that there's a more elegant way of expressing #00000000
, just use: @android/color/transparent
. It's easier to understand if you come back to that code some time later (Yeah, I know that it's just an ARGB number anyway ;-)).
Simply set your list color, using the methods below:
android:cacheColorHint="#000000"
or in your Java code:
listView.setCacheColorHint(0);
精彩评论