Android: ListView xml layout not showing background image when scrolled - android

I have an Activity with a ListView, I set the background image to the view programatically.
When I scroll down my list, the background image turns to white ( because my theme is Theme.Light.NoTitleBar).
How can I make it scroll with the blue background intact?
If the above point works, how can I change the text color of ListView to white instead of black?
Normal ListView
Scrolling ListView
Pressing ListView item

Use the attribute android:cacheColorHint="#000000" in ListView Tag
Regarding make TextView's color black or white, you can refer here to make a custom TextView for your ListView row, The extra work you have to do is just add another attribut inside TextView tag like this
android:textColor="#FFF" //or #FFFFFF for white

add a attribute on the ListView Tag
android:cacheColorHint="#00000000"// setting as a transparent color

This is due because of an optimization. To remove this, just set the cacheColorHint of your listView to transparent, like this: android:cacheColorHint="#00000000"
Full post here: http://android-developers.blogspot.fr/2009/01/why-is-my-list-black-android.html

You can Wrap that ListView inside on LinearLayout having same background and then remove ListView's Background that should work fine. :)

Please check this answer. I have got the same issue and it is fixed by putting view = null in adapter side.

Related

textview appears faded android

I am using a custom adapter to populate a listview.The list item is made of 2 textviews and the result is the following:
Any reason why the textview appears faded?
you might not have set the textcolor and tht could be a reason. set the textcolor to the textviews to black and it would be done.
Maybe because you have made your textViews in listView row as enabled:"false" .
If so give your textView textColor = "#000000" and otherwise also give textColor

List header/section color becomes dark while scrolling

I am using the this code to have section/headers in list.
http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/
I am setting the color with 50% alpha to list header and my window background color is transparent. So while scrolling header color becomes dark. Any idea how to overcome this.
and i have also set android:cacheColorHint="#00000000".
I had the same problem. I set the background color of the header view to the same background colour as the list's parent and it worked.
So I had a LinearLayout with a background colour of 'grey'.
The list is contained within this layout.
The list had android:cacheColorHint="#00000000" set in the XML and no background colour set.
The header view is loaded using LayoutInflater, inside my activity and set before the call to the list's setListAdapter.
The parent View (or main View) of the list header was also a LinearLayout with a background colour of 'grey'.
Hope this works for you.

Android - show footer divider but no list row divider

I have a list view which has a footer.
It displays numbers and at the bottom is the total.
I want to be able to show the rows without a divider between them. OTOH I DO want a divider before the summary row.
Is there any easy way to do this?
You can set android:dividerHeight to 0 in your list.
Then use custom layout for footer in which you add divider by yourself. For example, that can be a TextView with no text, android:layout_height set to 2 and android:background set to some color.
When you have custom layout for the footer, just add divider on top of it. It can be for example View of hight 2dp and different background color.
I had to do this programatically, since setting android:dividerHeight="0dip" in the XML didn't work for me:
getListView().setDividerHeight(0);

backgrounds in listview

i have a listview with a bunch of items in it, each item has its own background, the problem is that if i only have one item in a list, the rest of the "empty" slots of the list is black. I tried applying a background around the listview and also on the view that sorrounds it (relativeView) and i get a strange margin around the whole list like the picture at the bottom. The question i have is, how can i remove the actual "borders" around the list so it still fills upp its parent ? .
Remove any padding you may have used in your XML layout file.
Try putting in the following code in the listview's layout:
android:cacheColorHint="#00000000"
Change your listview height like this android:layout_height="fill_parent"
use android:fadingEdge="none" in listview in layout

Scrolling a ListView changes everything from White to Black [duplicate]

This question already has answers here:
Background ListView becomes black when scrolling
(12 answers)
Closed 9 years ago.
I have a custom list view and I want the background of the list to be white, so I do something like this which works great.
listView = (ListView) this.findViewById(R.id.listview);
listView.setBackgroundColor(Color.WHITE);
The problem is when you scroll the list the background of all the list items changes to black, which looks horrible.
I tried in my list view setting the background color to white. When I inflate the view I also tried setting the background color to white:
view.setBackgroundColor(Color.WHITE);
Both of these fix the problem of the scrolling background color, but now the item doesn't appear to be clickable even though it is. What I mean by that is the onClick still works fine, but the background doesn't flash to orange to let the user know he clicked it.
How can I have a white background in a list view, that stays white while scrolling, and does the normal list acitvity orange click background?
Thanks!
The solution is very simple, you also need to set the cache color hint to white: setCacheColorHint(Color.WHITE). You don't need to change the list items' background color.
ListView lv = getListView();
setCacheColorHint(0);
Set the cache color hint to zero.
Solution is very simple, you also need to set the cache color hint to black in xml.
android:cacheColorHint="#000000"
Android attempts to improve the performance of ListView scrolling by caching layout information. If you have long scrolling lists of data you should also set the the android:cacheColorHint property on the ListView declaration in the Activity’s AXML definition (to the same color value as your custom row layout’s background). Failure to include this hint could result in a ‘flicker’ as the user scrolls through a list with custom row background colors.
So give the same color to the listitem's background and android:cacheColorHint.you can refer below code.
In my Adapter layout I gave as
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ADAPTER_CONTAINER_PRIMARY"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FAFAEE"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center">
.....
And in the List view
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/LIST_GRID_LIST_INSTANCES"
android:focusableInTouchMode="true"
android:smoothScrollbar="true"
android:divider="#drawable/Gray"
android:dividerHeight="0.05dp"
android:cacheColorHint="#FAFAEE"
android:background="#drawable/round"/>
If your ListView is drawn atop a more complex background -- say, a bitmap or gradient -- then you may need to disable the scroll cache entirely. I ended up setting android:scrollingCache="false" on my ListView to resolve this issue.
http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:scrollingCache

Categories

Resources