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

戏子无情 提交于 2019-12-09 00:25:41

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5696422/adding-a-footer-view-to-a-multi-column-gridview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!