删除列表视图项下面的行

时间:2014-08-19 15:36:36

标签: android android-listview

我有一个按钮,可以将项目添加到列表视图中,每个项目之间有一条线。有关如何删除该行的任何想法吗?

这是单个项目布局XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

<EditText
    android:id="@+id/subjectname"
    android:layout_width="0sp"
    android:layout_height="fill_parent"
    android:layout_weight="2"
    android:gravity="center_vertical"
    android:hint="@string/subjectname"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<EditText
    android:id="@+id/subjectmark"
    android:layout_width="0sp"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:gravity="center"
    android:hint="@string/subjectmark"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<ImageButton
    android:id="@+id/remove"
    android:layout_width="@dimen/width_button"
    android:layout_height="fill_parent"
    android:contentDescription="@string/app_name"
    android:onClick="removeClick"
    android:background="@drawable/custombutton1"
    android:src="@drawable/ic_action_discard" />
</LinearLayout>

这是listview布局XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ListViewActivity" >

<Button
    android:id="@+id/addsubject"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="20dp"
    android:text="@string/addsubject"
    android:textColor="@color/white"
    android:background="@drawable/custombutton1" />

<ListView
    android:id="@+id/subject_list_item"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    tools:listitem="@layout/subject_list_item"
    android:layout_below="@+id/addsubject" >

</ListView>


</RelativeLayout>

希望有一个解决方案。提前谢谢!

1 个答案:

答案 0 :(得分:1)

列表项之间的行是分隔符。您可以使用XML轻松删除它;只需将以下内容添加到ListView:

        android:divider="@null"
        android:dividerHeight="0dip"

那会为你删除分隔符。