Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Endless Gridview

I have looked at lots of implementations of endless lists. One of them is https://github.com/commonsguy/cwac-endless

All of them are using listviews. And all of them are simply adding another row to the list. But when we consider Gridview (like in Google Play Store) and add the loading view as another item in the grid, it looks ugly. How can I achive the same thing in the Play Store?

like image 750
tasomaniac Avatar asked Jun 06 '12 22:06

tasomaniac


People also ask

How many types of GridView are there in flutter?

In Flutter, the two GridView is mostly used.

What is gridDelegate flutter?

SliverGridDelegate gridDelegate. A delegate that controls the layout of the children within the GridView. The GridView, GridView. builder, and GridView. custom constructors let you specify this delegate explicitly.

Is GridView scrollable flutter?

GridView class Null safety. A scrollable, 2D array of widgets.

What is the use of GridView in flutter?

GridView is a widget in Flutter that displays the items in a 2-D array (two-dimensional rows and columns). As the name suggests, it will be used when we want to show items in a Grid. We can select the desired item from the grid list by tapping on them.


2 Answers

i have write a scroll listener and set this scroll listener to my grid view . please correct me if found error.

EG:

final GridView g = (GridView) findViewById(R.id.myGrid);
        g.setAdapter(new ImageAdapter(this));
        EndlessScrollListener scrollListener=new EndlessScrollListener(g,new RefreshList() {

            @Override
            public void onRefresh(int pageNumber) {
                System.out.println("On Refresh invoked..");

            }
        });
        g.setOnScrollListener(scrollListener);

/////////////////////////////////////////////////////////////////////////

import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.GridView;

public class EndlessScrollListener implements OnScrollListener {

    private GridView gridView;
    private boolean isLoading;
    private boolean hasMorePages;
    private int pageNumber=0;
    private RefreshList refreshList;
    private boolean isRefreshing;

    public EndlessScrollListener(GridView gridView,RefreshList refreshList) {
        this.gridView = gridView;
        this.isLoading = false;
        this.hasMorePages = true;
        this.refreshList=refreshList;
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        if (gridView.getLastVisiblePosition() + 1 == totalItemCount && !isLoading) {
            isLoading = true;
            if (hasMorePages&&!isRefreshing) {
                isRefreshing=true;
                refreshList.onRefresh(pageNumber);
            }
        } else {
            isLoading = false;
        }

    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {

    }

    public void noMorePages() {
        this.hasMorePages = false;
    }

    public void notifyMorePages(){
        isRefreshing=false;
        pageNumber=pageNumber+1;
    }

    public interface RefreshList {
        public void onRefresh(int pageNumber);
    }
}
like image 144
Bytecode Avatar answered Sep 21 '22 22:09

Bytecode


Well, to literally use the same technique as is used in EndlessAdapter, you might add N items to the grid, where N is your number of columns.

Another approach is to detect when the user has scrolled near the bottom, then kick off the background work to load in more stuff. I don't have a link handy, but what I've seen uses an OnScrollListener to detect your scroll position as it changes.

like image 31
CommonsWare Avatar answered Sep 18 '22 22:09

CommonsWare