views:

341

answers:

3

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?

A: 

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

zehrer
That's exactly what I want to know how to add dividers from adapter. If you have some idea then please let me know.
sunil
Just override getView, see http://android.amberfog.com/?p=296 for an example.
zehrer
I have managed to do it. Thanks a lot to everyone for helping me out in this.
sunil
A: 

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.

Janusz
I didn't get you how can one add divider at the bottom of each row. I have one xml file row.xml. How to add divider in this row.xml and change its height at runtime.
sunil
Thanks a lot. Atlast I managed to do it with your suggestion.
sunil
A: 

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

Ricardo Villamil
Do I need to write this code in getView method of adapter? I am not using ListActivity for listview.
sunil
This will not allow you to have divider with a different height.
Janusz
@sunil, no, this code goes in your Activity (you're using a ListActivity, right?), probably onCreate(). If you need different heights per row, then Janusz is right, in this case you'll have to add the divider to each row and change height programmatically in adapter's getView()
Ricardo Villamil