简体   繁体   English

将页脚添加到GridView Android

[英]Add a footer to a GridView Android

I am developing an android application for listing the products of an on-line store. 我正在开发一个用于列出在线商店产品的android应用程序。 For this I have used a GridView for that. 为此,我为此使用了GridView But inside a category could be a big number of products, so I have to implement a feature like, "Loading on demand", with a button at the end of a gridView telling (Load More). 但是在一个类别中可能有大量产品,因此我必须实现一个功能,例如“按需加载”,并在gridView的末尾显示一个按钮(“加载更多”)。 Of course this button will be visible only if the GridView has reached the end of the items. 当然,只有当GridView到达项目末尾时,此按钮才可见。 But I dont how to do it. 但是我不怎么做。 Below is my solution so far, but the button is not visible when gridview goes at the end. 到目前为止,下面是我的解决方案,但是当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>

Suggestions or other solution will be more than welcome :) 建议或其他解决方案将非常受欢迎:)

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

as you implement and add this listener to your Gridview this will detect for the end of Gridview as scroll position was at end of list just get more data. 在实现并将此侦听器添加到Gridview时,这将检测到Gridview的结尾,因为滚动位置位于列表的末尾,只是获取了更多数据。 And during the loading data you need one flag to load data at once when the scroll position goes to end. 在加载数据期间,滚动位置结束时,您需要一个标志来立即加载数据。 So if data is loading and during that time you scroll up then scroll down then it will not get more data for dupplication. 因此,如果正在加载数据,并且在此期间您向上滚动然后向下滚动,则将不会获得更多用于重复数据处理的数据。

    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