繁体   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