开发者

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 开发者_如何学GoListView? 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜