Is it possible to add a footer View to a GridView (which has multiple columns) that behaves like a footer of a ListView? So this footer View (e.g. a pager view) appears only when the user scrolls to the bottom of the GridView, and it has the width of the whole screen, not only 1 grid element?
Adding a footer View to a multi-column GridView in Android?
Asked Answered
No, sorry, GridView
does not offer this sort of capability.
You mention using this for a "pager view". If, by that, you mean a "click here for more" entry, I'd just lazy-load the data once the end of the current grid data is reached. My EndlessAdapter
handles that, and while I have not tried it with GridView
, it may work -- leastways, I think it should.
In the gridview adapter you can do this:
@Override
public int getCount() {
return (footerView == null) ? super.getCount() : super.getCount() + 1;
}
public void setFooterView(View v) {
footerView = v;
}
// create a new view item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
if (footerView != null && position == getCount()-1) {
return footerView;
}
ViewHolder holder;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater lyinflater = LayoutInflater.from(mContext);
View view = lyinflater.inflate(getLayoutItemId(), null);
...
holder = new ViewHolder();
...
convertView = view;
view.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
...
return convertView;
}
EDIT Sorry I did not read the last part
and it has the width of the whole screen
Sorry... after try your answer it's a bug :/ .... it's create many footerViews ... –
Synodic
To solve the bug by adding this code: if (convertView!=null && convertView.findViewById(R.id.footerView) != null) { convertView = null; } –
Synodic
© 2022 - 2024 — McMap. All rights reserved.