问题描述
我已经看过很多无尽的列表实现。其中之一是 https://github.com/commonsguy/cwac-endless
I have looked at lots of implementations of endless lists. One of them is https://github.com/commonsguy/cwac-endless
所有这些都在使用列表视图。而所有这些都只需添加另一行到列表中。但是,当我们考虑的GridView(如在谷歌Play商店),并添加加载视图中的其他项目并网发电,它看起来丑陋。我怎样才能achive Play商店同样的事情?
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?
推荐答案
我有写一个滚动监听器,并设置这个滚动监听到我的网格视图。请纠正我,如果发现错误。
i have write a scroll listener and set this scroll listener to my grid view . please correct me if found error.
例如:
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);
}
}
这篇关于无尽的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!