Aamirkhan
Aamirkhan

Reputation: 5794

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?

Upvotes: 5

Views: 1568

Answers (4)

Manoj Kumar
Manoj Kumar

Reputation: 587

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..

Upvotes: 3

Android Stack
Android Stack

Reputation: 4314

you can add it to getview Methoid as follow :

public View getView(int position, View convertView, ViewGroup parent) {     
    if(items.get(position).get("name").startsWith("-")){    
       View divider = mInflater.inflate(R.layout."yourlayout",null);
        return divider;         } 

also, you must add item names starting with "-" where you want to add a divider.

Hope this helpful

Upvotes: 1

Herry
Herry

Reputation: 7087

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

Upvotes: 1

pepyakin
pepyakin

Reputation: 2235

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

Upvotes: 2

Related Questions