Skip to content Skip to sidebar Skip to footer

Android Delete From Listview

I have listview that contain checkbox and an image when the checkbox is clikced I show a button at bottom of the screen that perform deletion, but when listview height more ,then t

Solution 1:

Do you mean you wish for the delete button to be always visible even when the list contents are larger than the list control?

If that's the case try setting the layout_weight of your ListView to 1 and see if that solves your problem.


Solution 2:

Put ListView in ScrollView (so one will be able to scroll entire list), like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/mainView"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ListView
        android:id="@+id/listView"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:choiceMode="singleChoice"
        android:headerDividersEnabled="true">
    </ListView>
</ScrollView>
</LinearLayout>

Solution 3:

I have had a similar issue in the past. I found that using a relative layout and defining the button before the list solved my issues. Lets consider the following.

<?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="fill_parent"
    >
    <Button
        android:id="@+id/someButtonId"
        android:background="@drawable/gray_button"
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:layout_alignParentBottom="true"
        android:text="@string/some_button_value"
        android:textColor="@color/button_text"
        />

    <ListView
        android:id="@+id/someList"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/someButtonId"
     />
</RelativeLayout>

Here I have defined a Relative layout, the layout will occupy the full screen's width and height. I then place the button on the bottom of the RelativeLayout. My expectation is that the list will be placed above the defined button, and fill the remainder of the screen with list contents. Because we are telling the list View to be placed above the button, it will never grow large enough to cover the button causing the list view to mask the button clicks from the user.

hope this helps.


Post a Comment for "Android Delete From Listview"