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.
Actually you can create layout with two columns and use ListView. In getView you should manipulate with columns and set there some data.
Also you can create just one column in first and last row. It will look like header or footer.
Besides, you can look through these links:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.