3

So I have a rather annoying issue with a listview. My app was working just fine until the Android 2.3.3 update on my Droid 2. (Still seems to work fine on a Samsung Evo)

There are a few aspects of this issue. 1. The background is always gray in empty slots. 2. The last entry in the list appears to be invisible until it is selected. When selected you can see the black text, but no background. 3. Other/Older entries in the list do show with the correct background color.

I have tried quite a few things, and nothing seems to fix this. Thoughts?

Listview definition

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="wrap_content" 
 android:gravity="left|center"
 android:layout_width="wrap_content" 
 android:layout_alignParentBottom="true"
 android:paddingLeft="1px">
 <TextView android:text="" 
 android:id="@+id/list_view_text_view"
 android:layout_width="wrap_content" 
 android:textSize="13sp"    
 android:singleLine="false"
 android:layout_height="wrap_content"
 android:layout_marginLeft="1sp">
</TextView>


</LinearLayout>

Main Layout of listview

         <ListView android:id="@+id/ListView01" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:layout_alignRight="@+id/Button06" 
        android:layout_below="@+id/TextView01" 
        android:layout_alignLeft="@+id/TextView01"
        android:layout_marginBottom="2sp"
        android:layout_marginRight="2sp"
        android:layout_marginLeft="2sp"
        android:layout_above="@+id/EditText01" 
        android:transcriptMode="normal"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false"
        android:gravity="bottom"
 >
 </ListView>

Listveiw Adapter

private class EfficientAdapter extends BaseAdapter {
       private LayoutInflater mInflater;

       public EfficientAdapter(Context context) {
       mInflater = LayoutInflater.from(context);

       }

       public int getCount() {
       return comment_list.size();
       }

       public Object getItem(int position) {
       return position;
       }

       public long getItemId(int position) {
       return position;
       }
       public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder;

       if (convertView == null) {
       convertView = mInflater.inflate(R.layout.listview, null);
       holder = new ViewHolder();
       holder.text = (TextView) convertView
       .findViewById(R.id.list_view_text_view);

       convertView.setTag(holder);
       } else {
       holder = (ViewHolder) convertView.getTag();

       }

       holder.text.setText(comment_list.get(position).toString());

       return convertView;
       }

       class ViewHolder {
       TextView text;
       }
       }

This is the code i use to try and set the background in my main routine.

        list_view_comments.setBackgroundResource(R.color.color_con);
        list_view_comments.setDrawingCacheBackgroundColor(R.color.color_con);
        list_view_comments.setBackgroundColor(R.color.color_con);
        list_view_comments.setCacheColorHint(R.color.color_con);
user602622
  • 101
  • 3
  • 10

3 Answers3

12

Your issue is the same as this issue on SO... Listview background is grey on Droid 3

Here is the solution that Motorola gives us as a workaround... http://community.developer.motorola.com/t5/MOTODEV-Blog/Why-Does-My-ListView-Look-Different/ba-p/17462

Basically they (Motorola) are using a customized theme that you must override using attributes like

android:overScrollFooter="@null"

Edit - The link above no longer works for some reason. However, as Kevin said in the comments, the solution will still work.

Community
  • 1
  • 1
rf43
  • 4,385
  • 3
  • 23
  • 28
1

Hi use this may be it is helpful to you.

list_view_comments.setBackgroundColor(getResources().getColor(R.color.color_con));

Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
kalpana c
  • 2,739
  • 3
  • 27
  • 47
  • I think I already tried this, (Read this possible solution in another post). I don't think it work but I will check again tonight to be sure. – user602622 Sep 23 '11 at 13:55
  • Yeah as I thought, list_view_comments.setBackgroundResource(R.color.color_con); does the exact same thing as list_view_comments.setBackgroundColor(getResources().getColor(R.color.color_con)); – user602622 Sep 24 '11 at 16:37
  • So i have half answered my own question. The last item shows up when ya set android:footerDividersEnabled="true" instead of false. Kinda stupid that setting a footer divider would make the last item in the list transparent. – user602622 Sep 24 '11 at 16:41
  • Still cannot get the empty parts of the listview to not be grey. None of the following work list_view_comments.setBackgroundResource(R.color.color_con); list_view_comments.setBackgroundColor(getResources().getColor(R.color.color_con)); list_view_comments.setDrawingCacheBackgroundColor(R.color.color_con); list_view_comments.setBackgroundColor(R.color.color_con); list_view_comments.setCacheColorHint(R.color.color_con); – user602622 Sep 24 '11 at 16:42
1

How to draw a ListView in OS v2.3 so that the extra space below your last row item displays your specified background instead of the gray default footer background color:

overScrollFooter is unacceptable to most builds.
height="wrap_content" by itself only works if there are no other widgets below your ListView. Removing layout_alignParentBottom="true" can work, but can also damage the screen layout depending on the ListView's relationship with other widgets.

The most straightforward way to reduce the height of your ListView so there is no extra footer space that Motorola OS v2.3 wants to paint gray, is to wrap the ListView in another Layout such as a LinearLayout. Make the LinearLayout whatever size you wish and reduce the height of the internal ListView to "wrap_content". If you want more explanation and an example, navigate here: List View Footer Background on Android 2.3.3.

Community
  • 1
  • 1
David Manpearl
  • 12,362
  • 8
  • 55
  • 72