首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向GridView Android中添加页脚

向GridView Android中添加页脚
EN

Stack Overflow用户
提问于 2014-09-01 09:00:36
回答 2查看 733关注 0票数 0

我正在开发一个android应用程序,用于列出网上商店的产品。为此,我使用了一个GridView。但是在一个类别中可能有大量的产品,所以我必须实现一个特性,比如“按需加载”(Loading),在gridView的末尾有一个按钮告诉我(加载更多)。当然,只有当GridView到达项的末尾时,才能看到此按钮。但我不知道怎么做。到目前为止,下面是我的解决方案,但是当gridview结束时,按钮是不可见的。

代码语言:javascript
复制
<?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>

欢迎您提出建议或其他解决方案:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-09-01 09:24:17

当您实现此侦听器并将其添加到您的Gridview时,这将检测到Gridview的末尾,因为滚动位置位于列表的末尾,只需获取更多数据即可。在加载数据期间,当滚动位置结束时,需要一个标志来同时加载数据。因此,如果数据正在加载,并且在这段时间内向上滚动,然后向下滚动,那么它将不会获得更多的数据。

代码语言:javascript
复制
    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();
        }
    }
}
票数 0
EN

Stack Overflow用户

发布于 2014-09-01 09:10:42

使“加载更多”按钮成为GridView的一部分-在您的getView方法中,当“位置”对应于最后一项时,用按钮来充气布局。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25602259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档