滚动网格布局时还加载图像

我尽量让与适配器包含图像网格视图列表。 我还设置onscrolllistener作出不尽的名单。 但问题是,当我滚动,已加载从服务器再次加载的图像。

这里是我的代码:

public class ListProductLama extends Activity{ ArrayList<listBarang> list=new ArrayList<listBarang>(); ArrayList<listBarang> temp=new ArrayList<listBarang>(); ListAdapter adapter; int itemsPerPage = 4; int itemLoaded=0; boolean loadingMore = false; boolean full=false; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.adapter); Context ctx = getApplicationContext(); adapter=new ListAdapter(ctx, R.layout.adapterlist,list); ParsingXML parse=new ParsingXML(this, constant.GET_LIST_PRODUCT); parse.parse(); ListProductHandler handler=(ListProductHandler)parse.getMyExampleHandler(); ParsedListProductDataSet a=handler.getParsedData(); list=a.getList(); GridView grid=(GridView)findViewById(R.id.gridView1); grid.setAdapter(adapter); grid.setOnScrollListener(new OnScrollListener(){ @Override public void onScrollStateChanged(AbsListView view, int scrollState) {} @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if(!(full)){ int lastInScreen = firstVisibleItem + visibleItemCount; if((lastInScreen == totalItemCount) && !(loadingMore)){ Thread thread = new Thread(null, loadMoreListItems); thread.start(); } } } }); } //Runnable untuk load the items private Runnable loadMoreListItems = new Runnable() { @Override public void run() { loadingMore = true; //Reset the array that holds the new items temp=new ArrayList<listBarang>(); if(itemLoaded+itemsPerPage>=list.size()){ itemsPerPage=list.size()-itemLoaded; full=true; } int index=itemLoaded; for (int i = 0; i < itemsPerPage; i++) { temp.add(list.get(index)); index++; } runOnUiThread(returnRes); } }; private Runnable returnRes = new Runnable() { @Override public void run() { //Loop through the new items and add them to the adapter if(temp != null && temp.size() > 0){ for(int i=0;i<temp.size();i++) adapter.add(temp.get(i)); } adapter.notifyDataSetChanged(); itemLoaded+=itemsPerPage; loadingMore = false; } }; }

任何人都可以帮我吗?

分类:安卓 时间:2015-03-15 人气:0
本文关键词: GridView控件,机器人
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.398 (s). 10 q(s)