简体   繁体   中英

Adding a footer View to a multi-column GridView in Android?

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 (eg 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?

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

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM