Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a Footer has been added to a listview?

Tags:

android

I have a ListView to which i have added a footer. What call can I make on the list view to determine if a given footer is currently added to the listview?

  listView.findViewById(errorFooterid) ?

there does not seem to be a method

 view.containsView(viewReference)

Checking if an existing view is contained by another seems like a basic operation, but I don't know if there is a reliable way to check this in android.

Why does the SDK not support a clear and simple way to check for this? Even findByView(R.id.viewId) and null check is not very elegant way to do boolean check.

like image 930
Code Droid Avatar asked Nov 27 '22 21:11

Code Droid


2 Answers

If you had only one footer and want to know it's added or not, you would try to use

public int getFooterViewsCount ()
Since: API Level 1

Returns the number of footer views in the list. Footer views are special views at the bottom of the list that should not be recycled during a layout.
Returns

    The number of footer views, 0 in the default implementation. 

So if it return 0, your listview doesn't have footer

yourListView.getFooterViewsCount();
like image 95
Trung Nguyen Avatar answered Dec 09 '22 18:12

Trung Nguyen


You can find out the number of footer views by using the following code

listView.getFooterViewsCount();

If it returns 0, There is no footer views present.

like image 36
Nikhil Raj LR Avatar answered Dec 09 '22 20:12

Nikhil Raj LR