滚动网格视图运行到结尾时调用双重加载

时间:2015-11-09 03:29:03

标签: android gridview

我想在gridview的滚动运行到屏幕结束时加载更多数据,并且我在滚动侦听器上使用set,但是当滚动运行到结束时它会调用double load 我的EndScrollGridHome.java



public class EndScrollGridHome implements OnScrollListener {

	private int visibleThreshold = 0;
	private int currentPage = 0;
	private int previousTotal = 1;
	private boolean loading = true;
	private String url;
	private int totalItem = 10;
	ArrayList<Posts> arrData = new ArrayList<Posts>();
	BaseAdapter adapter;
	private Context context;
	
	private Dialog dialog1;
	Activity activiy;
	ArrayList<Posts> listPosts;
	ArrayList<Posts> listPostsGrid;
	ArrayList<Posts> listLoad;
	String name;
	String value;
	private ImageView imgLoad;
	private Animation anim;
	private ListView list_popular;
	private int mLastFirstVisibleItem;
	private boolean mIsScrollingUp;
	private Scrolling sCrolling;


	
	public EndScrollGridHome(ArrayList<Posts> listPostsGrid,
			BaseAdapter adap, Context context, String url,
			Activity activiy) {
		this.visibleThreshold = visibleThreshold;
		
		this.adapter = adap;
		this.context = context;
		this.url = url;
		
		this.activiy = activiy;
		this.listPosts = listPosts;
		this.listPostsGrid = listPostsGrid;
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		if (totalItemCount > totalItem) {
			totalItem = totalItemCount;
		}

		if (loading) {
			Log.d("OKKKKK", "" + totalItemCount + " " + visibleItemCount + " "
					+ firstVisibleItem + " " + visibleThreshold);

			if (totalItemCount > previousTotal) {
				loading = false;
				previousTotal = totalItemCount;
				currentPage++;
			}
		}
		if (!loading
				&& (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)&&firstVisibleItem!=0) {
			Log.d("Load more !",  totalItemCount+ " " +visibleItemCount +" "+firstVisibleItem);
			
			loading = true;

			

		}
	}

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

	}
}
&#13;
&#13;
&#13; 它与listview运行良好,所以我试图分割值,但它仍然是这样 如何只召唤一次?请帮我 非常感谢muck

0 个答案:

没有答案