1
votes

I realize there are many topics on this question and I have looked at them all. But I am still very confused why my ListView background remains black. I am able to change the background only when I change the background to my LinearLayout, which makes up my ListView rows, is set to a certain color. However, when I do set the background of my LinearLayout to a color, I am not able to view the selector.

I have set cacheColorHint="#00000000", android:scrollingCache="false", and even tried android:drawSelectorOnTop="true". I believe the problem might lie somewhere with either defining or creating my selector, because I have never been able to view my changes on the screen when I tested the application. But this is all speculation, since I can not fix my problem I really do not know what is wrong. Below you can view my code.

my selector: list_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" android:color="#80ff0000" /> <!-- focused -->
<item android:state_focused="true" android:state_pressed="true" android:color="#80ff0000" /> <!-- focused and pressed-->
<item android:state_pressed="true" android:color="#80ff0000" /> <!-- pressed -->
<item android:color="#ffffffff" /> <!-- default -->
</selector>

my ListView: main.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:background="#ffffffff">

<!-- List view -->
<ListView android:id="@+id/android:list" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:dividerHeight="0px"
    android:divider="#0099CC"
    android:listSelector="@drawable/list_background"
    android:drawSelectorOnTop="true"
    android:cacheColorHint="#00000000"
    android:scrollingCache="false"/>    

</RelativeLayout>

my LinearLayout: image_text_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:background="#00000000">

    <ImageView android:id="@+id/feed_image"
    android:layout_width="100dip" 
    android:layout_height="100dip"
    android:paddingTop="5dip"
    android:paddingRight="3dip"
    android:background="#00000000"/>

    <TextView android:id="@+id/job_text" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:textColor="#FF4444"
    android:paddingTop="5dip"
    android:paddingBottom="28dip" 
    android:paddingLeft="8dip"
    android:paddingRight="8dip"
    android:background="#00000000"/>
</LinearLayout>
1

1 Answers

1
votes

There might be two things.

One: You may need to make the LinearLayout ' android:clickable ' or ' android:focusable'. This is because by default a layouts are not clickable. Where the android default simple_list_item is.

Two: I also believe when dealing with custom rows, you need to assign your selector to the background of the custom row (image_text_layout.xml) LinearLayout and not to the listview. I'm not too sure.