Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put divider at particular position in an Android list view

I need to make a list view in which I want to have a divider at some position only not after every list item. I am using custom list view.

Is there any solution of this problem?

like image 595
Aamirkhan Avatar asked Mar 31 '12 07:03

Aamirkhan


3 Answers

you can you this xml file in list adapter class like

ItemsAdapter ItemsAdapter = new ItemsAdapter(EnterpriseFertilisersScreen.this,
                R.layout.list, Constant.FERTILIZERMANAGERARRAY);

R.layout."below xml file " and user as further white color.


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"

    android:background="@color/list_bg" >

    <TextView
        android:id="@+id/post"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_marginLeft="7dp"
        android:layout_toRightOf="@+id/bite_image"
        android:gravity="center_vertical"
        android:textColor="@android:color/white"
        android:textSize="20sp" />

</RelativeLayout>

If you have another issues, ask feel free..

like image 131
Manoj Kumar Avatar answered Nov 02 '22 23:11

Manoj Kumar


You can create Adapter for list, which will be place dividers as elements (via getView). This is standart android approach

like image 24
pepyakin Avatar answered Nov 02 '22 21:11

pepyakin


If you have used Custom ListView to show your .you need to make position where you need to show different View from xml by condition .you should have to do this in getView Method.

Either you need to see how this example use divider using CursorAdapter.

Check this https://github.com/cyrilmottier/ListViewTipsAndTricks/blob/master/src/com/cyrilmottier/android/listviewtipsandtricks/SectionedListActivity.java

like image 34
Herry Avatar answered Nov 02 '22 21:11

Herry