20
votes

I have a ListView with BaseAdapter. In XML, I specified item divider as red color with 10dip height.

    <ListView android:layout_width="fill_parent"
                android:layout_height="0px"
                android:id="@+id/lv"
                android:layout_weight="1"
                android:cacheColorHint="#00000000"
                android:divider="#FF0000"
                android:dividerHeight="10dip"
                android:fadingEdge="none">
    </ListView>

But, when the app runs, I didn't see the red dividers between items. Can someone tell me why? Thanks.

Edit: in my adapter code, I have the following code:

@Override
public boolean areAllItemsEnabled() {
    return false;
}

@Override
public boolean isEnabled(int position) {
    return false;
}

because I want control the onClick behavior of each item. I don't know whether the code above makes the dividers disappear.

1
May be android:layout_height="0px" can be a problem. - Yekmer Simsek
The list view is in a LinearLayout. The items are showing correctly, but the dividers are not showing. - Kai
Setting layout_height="0dip" or similar is the correct thing to do when you are also setting a layout_weight within a vertical LinearLayout because you want it to consume available space. - adamp
Even after I changed android:layout_height="0px" to android:layout_height="fill_parent", I still didn't see the dividers. - Kai
I just found out, returning false for isEnabled is the reason that the dividers were not showing up. Thanks for your help, friends. - Kai

1 Answers

4
votes

The layout is good and it should work. I just tested it myself and it did work for me. Try seeing what you have in your list item layout or your list activity class.

If that doesn't work I would recommend creating a normal list from the samples and give the list these attributes and see what happened.

Achie.