Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent divider in a listview

Tags:

android

I am creating a listiview programmatically. I keep a divider between listview elements. I wish to keep a transparent divider because I have a background image to be shown. I have tried the following code which does not work. Kindly help

setListAdapter(new ArrayAdapter<String>(this,R.layout.news,news));

ListView lv=getListView();

ColorDrawable sage= new ColorDrawable(this.getResources().getColor(Color.TRANSPARENT));

lv.setDivider(sage);

lv.setDividerHeight(20);
like image 415
kusi Avatar asked Nov 17 '11 05:11

kusi


4 Answers

Try this:

color.xml: (res > values > color.xml)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <drawable name="transperent_color">#00000000</drawable>    
</resources>

Now,use it like:

setListAdapter(new ArrayAdapter<String>(this,R.layout.news,news));
ListView lv=getListView();
lv.setDivider(this.getResources().getDrawable(R.drawable.transperent_color));
lv.setDividerHeight(20);
like image 142
Hiral Vadodaria Avatar answered Nov 04 '22 21:11

Hiral Vadodaria


@kusi if you have not setContentView(R.layout.yourlayout); then you should have to declare it and then in that layout file you have to declare this ListView

<ListView android:id="@android:id/list"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:divider="#00000000"
    android:dividerHeight="20dip"
    /> 

note that you must have to set id of this listview as android:id="@android:id/list" in case you have extends ListActivity in your Activity Class.

like image 35
Herry Avatar answered Nov 04 '22 21:11

Herry


this line brings it standardized, usable everywhere ... :)

getListView().setDivider(this.getResources().getDrawable(android.R.color.transparent));

if you also call -> setDividerHeight, call setDivider first.

good luck && have fun :=)

like image 10
cV2 Avatar answered Nov 04 '22 21:11

cV2


plz use following code for Transparent Divider in List View Its happen for following code

lv.setDivider(null);
like image 5
Hardik Gajjar Avatar answered Nov 04 '22 22:11

Hardik Gajjar