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.
and
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With