UI线程,主线程阻塞(blocking).新启一个线程,并由Handler来执行.
@Override public void onScroll(AbsListView view, final int firstVisibleItem, final int visibleItemCount, final int totalItemCount) { Thread songsList = new Thread(){ @Override public void run(){ firstItem = firstVisibleItem; visibleCout = visibleItemCount; totalCount = totalItemCount; Message message = new Message(); message.what = 2; handler.sendMessage(message); } }; songsList.start(); } Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 2: if ((firstItem + visibleCout == totalCount) && (totalCount != 0)) { if (refreshAble) { refreshAble = false; loading.setVisibility(View.VISIBLE); /** * 获取下一页数据 */ getData(++pageNo); } } break; default: break; } } };
http://developer.android.com/resources/articles/painless-threading.html