ApiDemos-->Views-lists-slow adapter学习

2020-12-13 03:58

阅读:383

标签:android   des   style   blog   http   java   

今天来按照apidemos提供的方法来实现slow loading的效果.

简单说下实现方法:

实现ListView.OnScrollListener ,监听到手势滑动的情况,当处于滚动状态时,将新显示的items 设置为Loading , 当离开屏幕时,才加载真实的数据.

设置数据时,要用到getFirstVisiblePosition属性来计算应该加载第几个item.

该小demo应该算是学习Android AsyncTask异步加载的基础.

soscw.com,搜素材

Main.java

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.testmyviewslistsactivateitems.R;

/**
 * 
 * @author Administrator 仿效果slow loading apiDemos -- Views -Lists - Slow Adapter
 */
public class Main extends ListActivity {

	private boolean mBusy = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setListAdapter(new SlowAdapter(this));
		// 设置选择模式为单选
		getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		// 首次加载设置选中items
		getListView().setItemChecked(0, true);
		getListView().setOnScrollListener(new OnScrollListener());
	}

	protected class OnScrollListener implements ListView.OnScrollListener {

		@Override
		public void onScrollStateChanged(AbsListView view, int scrollState) {
			switch (scrollState) {
			//The view is not scrolling.
			case OnScrollListener.SCROLL_STATE_IDLE:
				mBusy = false;
				int first = view.getFirstVisiblePosition();
				int count = view.getChildCount();
				for (int i = 0; i 
代码下载

Views-lists-slow adapter学习,soscw.com" href="http://www.soscw.com/infodetail-244952.html" target="_blank">ApiDemos-->Views-lists-slow adapter学习,搜素材,soscw.com

Views-lists-slow adapter学习,soscw.com" target="_blank">ApiDemos-->Views-lists-slow adapter学习

标签:android   des   style   blog   http   java   

原文地址:http://blog.csdn.net/aikongmeng/article/details/37069943


评论


亲,登录后才可以留言!