簡體   English   中英

將頁腳添加到GridView Android

[英]Add a footer to a GridView Android

我正在開發一個用於列出在線商店產品的android應用程序。 為此,我為此使用了GridView 但是在一個類別中可能有大量產品,因此我必須實現一個功能,例如“按需加載”,並在gridView的末尾顯示一個按鈕(“加載更多”)。 當然,只有當GridView到達項目末尾時,此按鈕才可見。 但是我不怎么做。 到目前為止,下面是我的解決方案,但是當gridview最后出現時,該按鈕不可見。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <com.twotoasters.jazzylistview.JazzyGridView
            android:id="@+id/ebuy_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:drawSelectorOnTop="true"
            android:horizontalSpacing="15dp"
            android:numColumns="2"
            android:verticalSpacing="15dp" />

        <TextView
            android:id="@+id/more"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/ebuy_now_background"
            android:clickable="true"
            android:onClick="loadMore"
            android:padding="15dp"
            android:text="Load More"
            android:textColor="@color/ebuy_color_second_strip"
            android:textSize="25sp" />

    </LinearLayout>

</ScrollView>

建議或其他解決方案將非常受歡迎:)

使“加載更多”按鈕成為GridView的一部分-當“位置”對應於最后一項時,在getView方法中,使用按鈕使布局膨脹。

在實現並將此偵聽器添加到Gridview時,這將檢測到Gridview的結尾,因為滾動位置位於列表的末尾,只是獲取了更多數據。 在加載數據期間,滾動位置結束時,您需要一個標志來立即加載數據。 因此,如果正在加載數據,並且在此期間您向上滾動然后向下滾動,則將不會獲得更多用於重復數據處理的數據。

    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    this.currentFirstVisibleItem = firstVisibleItem;
    this.currentVisibleItemCount = visibleItemCount;
}

public void onScrollStateChanged(AbsListView view, int scrollState) {
    this.currentScrollState = scrollState;
    this.isScrollCompleted();
 }

private void isScrollCompleted() {
    if (this.currentVisibleItemCount > 0 && this.currentScrollState == SCROLL_STATE_IDLE) {
        /*** In this way I detect if there's been a scroll which has completed ***/
        /*** do the work for load more date! ***/
        if(!isLoading){
             isLoading = true;
             loadMoreDAta();
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM