How to show a button at the end of an Android ListView

前端 未结 9 1160
臣服心动
臣服心动 2020-12-02 12:18

I want to show a button at the end of an Android list view. How can I achieve this?

I don\'t want to stick it to the activity bottom using alignparentbottom=

9条回答
  •  攒了一身酷
    2020-12-02 12:58

    1 If you want to add Button as the last element of the list view

    You must create custom ListAdapter for your ListView which will create a view with a Button in the getView method. You should decide how to return your custom view for the last element, you can hardcode it (return element count +1 in getCount method and return custom view in getView when position > element count) or you can add element to the structure you will be taking data from (Array, Cursor etc.) and check if field of element have certain value

    2 If you want to add element below list view

    You should use android:layout_width attribute and make ListView and "empty" TextView (you should use it to show users that list is empty and View rendering is completed) layout_weight greater than buttons layout_weight

    Check how it's done in Transdroids search Activity http://code.google.com/p/transdroid/source/browse/trunk/res/layout/search.xml

提交回复
热议问题