Question

I wanted to change the divider height dynamically. From whatever I have searched it seems that it is possible through setting divider as part of each item in ListView. But I am not very clear with this.

So, can someone be more specific as how can one make the divider as part of item in ListView?

Was it helpful?

Solution

A way to do this would be to include the divider at the bottom of each row. Now you have to set the height of the divider view in your getView method in your listadapter depending of the item you are showing at the moment.

OTHER TIPS

Nothing is better than explaining by picture. Here I found a screenshot from web. I made some mark on it.

This is what you want to achieve. enter image description here

You can make the divider as one of the items. enter image description here

Also, you can make the divider as a part of an item. enter image description here

Neither of the 2 solutions uses real divider provided by ListView. It should be set 0 height. Sounds silly but it does effective.

You could set android:footerDividersEnabled to false and add dividers in your adapter.

In your ListActivity call:

ListView lv = getListView();
lv.setDivider(divider);

where divider is a Drawable object which you can define or write in your code as you need to.

You can also call:

lv.setDividerHeight(2);

To change the height

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top