简体   繁体   English

将页脚视图添加到Android中的多列GridView?

[英]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? 是否可以向GridView(具有多列)添加页脚视图,其行为类似于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? 因此,仅当用户滚动到GridView的底部时,此页脚视图(例如寻呼机视图)才会出现,并且它具有整个屏幕的宽度,而不仅仅是1个网格元素?

In the gridview adapter you can do this: 在gridview适配器中,您可以执行以下操作:

@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. 不,抱歉, GridView不提供这种功能。

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. 我的EndlessAdapter处理这个问题,虽然我没有尝试使用GridView ,但它可能会工作 - 至少,我认为应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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