Divider disappears from last item in listview if footerview added
Asked Answered
V

5

10

If footer view added in ListView, then divider disappears from last item of ListView.

Even I have set android:footerDividersEnabled="true" with ListView and my footer view is just TextTiew.

Vella answered 14/4, 2011 at 10:11 Comment(0)
Z
20

The ListView implementation in Android never draws dividers between items that are disabled, which if you are just calling the addFooterView(View v) method then by default your footer will be.

Instead you need to call the addFooterView(View v, Object data, boolean isSelectable) method with isSelectable set to true. You can just pass null for the data object if you don't need it.

Zucker answered 14/4, 2011 at 10:14 Comment(2)
Yes, added a footerView like this: listView.addFooterView(view, null, true) , and it worked fine... thanksVella
this adds the divider, but introduces a worse problem. now the footer is clickable!Renascence
B
21

Setting isSelectable to true didn't work for me, maybe because I was also calling removeFooterView when my list was done loading.

What finally fixed it for me was setting android:layout_height to "fill_parent" instead of "wrap_content" on the ListView.

Buxom answered 2/8, 2011 at 16:22 Comment(2)
setting 'android:layout_height="fill_parent"' does the trick... thank u so much for the solution!!!!Arwood
Awesome thanks! just noting for future users, use match_parent for forward compatibility. Don't know when fill_parent will be deprecatedPitiable
Z
20

The ListView implementation in Android never draws dividers between items that are disabled, which if you are just calling the addFooterView(View v) method then by default your footer will be.

Instead you need to call the addFooterView(View v, Object data, boolean isSelectable) method with isSelectable set to true. You can just pass null for the data object if you don't need it.

Zucker answered 14/4, 2011 at 10:14 Comment(2)
Yes, added a footerView like this: listView.addFooterView(view, null, true) , and it worked fine... thanksVella
this adds the divider, but introduces a worse problem. now the footer is clickable!Renascence
O
14

This almost worked for me. I was after a divider after the last list item, but not after the footer as my footer was empty space. I ended up adding two footers, one selectable of zero height and one not selectable containing the padding.

TextView view = new TextView(this);
view.setLines(0);
TextView view1 = new TextView(this);
view1.setLines(4);
mListView.addFooterView(view, null, true);
mListView.addFooterView(view1, null, false);
mListView.setFooterDividersEnabled(true);
Ormazd answered 20/8, 2011 at 18:44 Comment(0)
E
8

Try setting the layout_height of the ListView to match_parent:

android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#333333"
android:dividerHeight="1px"

When the layout_height is set to wrap_content it might skip the bottom divider:

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#333333"
android:dividerHeight="1px"
Enterogastrone answered 16/9, 2012 at 17:32 Comment(0)
M
1

Head through the wall approach, but reliable, is to manually add divider as a footer view.

ListView myListView = (ListView) view.findViewById(R.id.my_list_view);
myListView.addFooterView(getInflater().inflate(R.layout.horizontal_divider, myListView, false), null, false);
myListView.addFooterView(getInflater().inflate(R.layout.the_original_footer_view, myListView, false), null, false);

Where the layout file would look like this:

<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="1px"
    android:background="?android:attr/dividerVertical" />

This approach can be used to add the divider easily even after the last footer, regardless it is selectable, enabled or anything - it just stays there.

Note the height is 1px rather than 1dp. Though against all recommendations, at least at the device I tested this gives the same divider height as ListView, while 1dp does not.

Mong answered 25/3, 2014 at 22:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.