addView for GridView

Ask by : onemach June 20, 2013 19:19

I want to add a footer view for GridView.

I find in the documentation GridView has 2 inherited addView(View child) method.

From class android.widgetAdapterView

void addView(View child)

This method is not supported and throws an UnsupportedOperationException when called.


From class android.view.ViewGroup

void addView(View child)

Adds a child view.

It seems I should use the latter. But how can I call this particular inherited method?

View original question

Answer by : EricNovember 04, 2012 04:07

You don't. It overwrites the original with a UnsupportedOperationException because it's.. well.. not supported.

You should be editing the adapter instead. Depending on your implementation, this will look different. But, you just have to add more data to the adapter, and call .notifyDataSetChanged() on the adapter, and your GridView will add the view by itself.

A footer view should either be a separate View after your GridView, or you will have to maintain its position in the adapter's list to always be last whenever you add new items.

View original answer