Maybe you want to call addHeaderView() or addFooterView() in GridView, which it does not have.
It's nature that we want to add header view or a footer view to a GridView. Maybe your have been searching a long time like me, but finally find no solution.
Here, I will give out an solution.
I post this answer just want people who come here can get what the want.

GridViewWithHeaderAndFooter gridView = (GridViewWithHeaderAndFooter) v.findViewById(R.id.ly_image_list_grid);
LayoutInflater layoutInflater = LayoutInflater.from(this);
View headerView = layoutInflater.inflate(R.layout.test_header_view, null);
View footerView = layoutInflater.inflate(R.layout.test_footer_view, null);
gridView.addHeaderView(headerView);
gridView.addFooterView(footerView);
It'a single file project, now it hosts at GitHub: https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter
You can follow the link above to access the code. Happy coding.
To add a Header to the GridView, use the HeaderGridView by Google.
Just copy this class into your project and use it instead of the default GridView, and you will be able to add header using the following line:
gridView.addHeaderView(customView);
Source: answer
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