20

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.

Kai
  • 3,775
  • 10
  • 39
  • 54
  • 8
    I just found out, returning false for isEnabled is the reason that the dividers were not showing up. Thanks for your help, friends. – Kai Apr 07 '11 at 22:09
  • May be android:layout_height="0px" can be a problem. – Yekmer Simsek Apr 07 '11 at 21:38
  • The list view is in a LinearLayout. The items are showing correctly, but the dividers are not showing. – Kai Apr 07 '11 at 21:42
  • 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 Apr 07 '11 at 21:45
  • Even after I changed android:layout_height="0px" to android:layout_height="fill_parent", I still didn't see the dividers. – Kai Apr 07 '11 at 21:54

1 Answers1

5

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.

achie
  • 4,716
  • 7
  • 45
  • 59
  • 18
    I just found out, returning false for isEnabled is the reason that the dividers were not showing up. – Kai Apr 07 '11 at 22:44
  • is it possible to set the isEnabled to false, yet still show the dividers? EDIT: never mind. you can set the listSelector to transparent. wonder if there is another way to do it. – android developer Feb 01 '14 at 18:50