2011-04-17 44 views
2

是否可以添加一個頁腳視圖到一個GridView(它有多個列),其行爲像一個ListView的頁腳?因此,僅當用戶滾動到GridView的底部時,此頁腳視圖(例如,傳呼機視圖)纔會出現,並且它具有整個屏幕的寬度,而不僅僅是1個網格元素?在Android中添加頁腳查看多列GridView?

回答

4

不,對不起,GridView不提供這種功能。

你提到使用這個「尋呼機視圖」。因此,如果你的意思是「點擊此處查看更多」條目,則只需在達到當前網格數據的末尾時延遲加載數據。我的EndlessAdapter處理,雖然我還沒有用GridView嘗試過,但它可能工作 - 最起碼,我認爲它應該。

4

在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; 
} 

編輯 對不起,我沒看過的最後一部分

,它有整個屏幕

的寬度
+0

對不起...在嘗試你的答案後,這是一個錯誤:/ ....它的創建很多footerViews ... – 2014-05-19 21:19:40

+0

通過添加以下代碼來解決該錯誤:if(convertView!= null && convertView.findViewById(R.id.footerView)!= null){ convertView = null; } – 2014-05-19 22:03:26