Skip to content Skip to sidebar Skip to footer

Can I Set A Footer To An Empty Listview In Android?

What i want to know? I was little curious about if i can add a footer to an empty ListView in android. I checked the documentation of ListView footer but they haven't mentioned any

Solution 1:

I am posting this just in case if anyone is looking for the similar functionality as mine. Answer is NO, you can't add a footer view to an empty ListView. To achieve the similar functionality you will have create your own layout & add it explicitly to the ListView & manage it's state.

Rupesh

Solution 2:

I suppose you use a ListAdapter on your ListView? Just add a "footer item" to your ArrayList/ whatever of list items. In the getView method, check if the item is your footer, then set a custom layout on it where you have your buttons or whatever. Just ask if it's not clear what I mean.

Solution 3:

To achieve this scenario when list is empty: Create to adapter and assign them layouts:

  1. when list is not empty assign adapter to it with layouts.
  2. when list is empty assign list a dummy adapter and with one initial value.
  3. donot assign value to dummy layout in getview or give size to dummy view to 0 dp. so you can achieve this scenario... ask further i have solve this scenario

Solution 4:

public void addFooterView (View v)
Added in API level 1Add a fixed viewto appear at the bottom of the list. If addFooterView iscalled more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.
Note: Whenfirst introduced, this method could only be called before setting the adapter with setAdapter(ListAdapter). Starting with KITKAT, this method may be calledatany time. If the ListView's adapter does not extend HeaderViewListAdapter, it will be wrapped with a supporting instance of WrapperListAdapter.
Parameters
v
The view to add.

Post a Comment for "Can I Set A Footer To An Empty Listview In Android?"