How to place a delimiter in a specific position as an Android list

I need to create a list view in which I want to have a separator at some position only after each list item. I use custom list view.

Is there any solution to this problem?

+5
source share
4 answers

you can use this xml file in a list adapter class like

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

R.layout. "below the xml file" and the user as the next 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 other problems, ask, feel free.

+3
source

You can create an adapter for the list that will place the delimiters as elements (via getView). This is the standard approach for Android.

+2

getview Methoid :

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;         } 

, "-", .

,

+1

All Articles