Android Computer / Informatik

ListView Divider Settings Order

Hey everybody,

today i experienced a little „problem“ with a ListView that i want to share with you.

I had a ListView defined in an XML layout file:

[sourcecode language=“xml“]


For some reason i now needed to create it programmatically. So i did the following to create an equivalent ListView:

[sourcecode language=“java“]
ListView listView = new ListView(context);
listView.setDivider(new ColorDrawable(0));

But somehow the divider didn’t show up anymore. So what was the reason for that? It was just the order! Somehow setting the divider color after setting it’s height doesn’t work and the height is reset to 0. So changing the order to first setting the color and then setting the height fixed the problem!

Gr33tz Goddchen