在android中,如何使用标题分隔列表?

在android中,如何使用标题分隔列表?,android,android-layout,android-listview,navigation-drawer,Android,Android Layout,Android Listview,Navigation Drawer,我正在尝试在drawerLayout中为ListView添加节separator标题,但我看不到分隔符,只看到标题 这是我的代码: public class MainActivity extends ActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layo

我正在尝试在
drawerLayout
中为
ListView
添加节
separator
标题,但我看不到
分隔符,只看到标题

这是我的代码:

public class MainActivity extends ActionBarActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    public Cursor cursor;
    public Cursor cursorsex;
    public ArrayList<String> array;
    public ArrayList<String> arraysex;
    private ArrayAdapter<String> listAdapter ;
    private ArrayAdapter<String> listAdaptersex ;
    private ListView mDrawerList;
    private ListView mDrawerListsex;
.....
Connection to sqlite
.....
        sql = db.openDataBase();
        cursor = sql.rawQuery("SELECT Title FROM WebSite_CategoryBack WHERE ParentID=0;", null);
        array = new ArrayList<String>();
        while(cursor.moveToNext()){
            Titel_Drawer = cursor.getString(cursor.getColumnIndex("Title"));
            array.add(Titel_Drawer);
        }
        cursor.close();


        cursorsex = sql.rawQuery("SELECT Title FROM WebSite_CategoryBack WHERE ParentID=0;", null);
        arraysex = new ArrayList<String>();
        while(cursorsex.moveToNext()){
            Titel_Drawer = cursorsex.getString(cursorsex.getColumnIndex("Comment"));
            arraysex.add(Titel_Drawer);
        }
        cursorsex.close();


        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        mDrawerListsex = (ListView) findViewById(R.id.sex);


        listAdapter = new ArrayAdapter<String>(this, R.layout.drawer_list,R.id.textView, array);
        mDrawerList.setAdapter( listAdapter );

        listAdaptersex = new ArrayAdapter<String>(this, R.layout.xxx,R.id.xxx, arraysex);
        mDrawerListsex.setAdapter( listAdaptersex );
   }
}
这是
抽屉列表.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/xxx"/>
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/textView"/>
<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    <!-- The main content view -->
    <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    <LinearLayout
        android:id="@+id/drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_gravity="start">
        <TextView
            android:layout_width="240dp"
            android:layout_height="25dp"
            android:textSize="20sp"
            android:gravity="center"
            android:text="@string/prof"
            android:background="@drawable/drawer_title_shape" />
    <!-- The navigation drawer -->

    <ir.makarem.extentions.ClearableEditText
        android:id="@+id/SearchEdittxt"
        android:drawableLeft="@drawable/ic_action_search"
        android:layout_width="240dp"
        android:layout_height="35dip"
        android:background="@drawable/textlines"
        android:gravity="right"
        android:hint="@string/action_search" />

    <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#FFDDDDDD"/>


        <ListView
            android:id="@+id/sex"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#FFDDDDDD"/>


</LinearLayout>
</android.support.v4.widget.DrawerLayout>
例如,我需要看到像这张照片。


我为标题添加了两个
TextView
,为列表视图添加了两个
ListView
,您需要为您的
ListView
设置一个分隔符:(代码示例)

或在.xml中设置分隔符:

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="#FFFFFF"
        android:dividerHeight="2px" >
    </ListView>

您必须使用节头列表视图来实现此功能


reference link

Hi@Philipp Jahoda。我的项目中有两个列表视图,我应该为setDivider使用witch-one列表视图?这完全取决于您。如果希望ListView有一个分隔符,可以设置一个分隔符,否则不设置。我真的不明白你的问题。丑陋的代码。尝试将查询与布局代码分开。必须为此添加节标题listview。
    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="#FFFFFF"
        android:dividerHeight="2px" >
    </ListView>