Android Delete from listview

前端 未结 3 1497
不知归路
不知归路 2021-01-28 19:11

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 ,the

相关标签:
3条回答
  • 2021-01-28 19:26

    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>
    
    0 讨论(0)
  • 2021-01-28 19:35

    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.

    0 讨论(0)
  • 2021-01-28 19:53

    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.

    0 讨论(0)
提交回复
热议问题