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:
<ListView android:id="@+id/ListView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:dividerHeight="5px" android:divider="#000000" android:scrollbars="none" />
For some reason i now needed to create it programmatically. So i did the following to create an equivalent ListView:
ListView listView = new ListView(context); listView.setDivider(new ColorDrawable(0)); listView.setDividerHeight(5); listView.setVerticalScrollBarEnabled(false);
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!