AndroidカスタムListViewでは、下部ページング・リフレッシュと上部ドロップダウン・リフレッシュを実現


プロジェクト開発では、データが大きすぎる場合、ページングロードまたはドロップダウンリフレッシュを行い、一度のロードの長すぎる待ち時間を緩和する必要があります.このブログの例では、カスタマイズされたListViewによる下部ページングロードと上部ドロップダウン・リフレッシュの効果について説明します.
効果図:
一.ListView下部ページングロード
下全体をページングしてロードし、主にいくつかのステップに分けます.
1.下部のカスタムビューをロードします.
2.OnScrollListenerリスニングイベントに応答して、onScrollメソッドは最後に表示されたView ItemとtotalItemCount全体を記録する.onScrollStateChangedの状態が変化すると、
最後までスライドし、SCROLL_の状態でスライドします.STATE_IDLEは、下部にViewをロードすることを表示し、カスタムロードインタフェースの実現を開始します.
3.データのロードが完了すると、下部のドロップダウンビューを非表示にする.
カスタム下部ドロップダウン・ロードPaginationListViewコードは次のとおりです.
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.example.paginationrefreshlistdemo.listview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;

import com.example.paginationrefreshlistdemo.R;

public class PaginationListView extends ListView implements OnScrollListener{
	//  View
	private View footerView;
	//ListView item  
	int totalItemCount = 0;
	//     Item
	int lastVisibleItem = 0;
	//      
	boolean isLoading = false;
	
	public PaginationListView(Context context) {
		super(context);
		initView(context);
	}
	
	public PaginationListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
		
	}

	public PaginationListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView(context);
	}
	
	/**
	 *    ListView
	 */
	private void initView(Context context){
		LayoutInflater mInflater = LayoutInflater.from(context);
		footerView = mInflater.inflate(R.layout.footer, null);
		footerView.setVisibility(View.GONE);
		this.setOnScrollListener(this);
		//    View
		this.addFooterView(footerView);
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		//      ,       not scrolling
		if(lastVisibleItem == totalItemCount && scrollState == SCROLL_STATE_IDLE){
			if(!isLoading){
				isLoading = true;
				//    
				footerView.setVisibility(View.VISIBLE);
				//    
				onLoadListener.onLoad();
			}
		}
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		this.lastVisibleItem = firstVisibleItem + visibleItemCount;
		this.totalItemCount = totalItemCount;
	}
	
	private OnLoadListener onLoadListener;
	public void setOnLoadListener(OnLoadListener onLoadListener){
		this.onLoadListener = onLoadListener;
	}
	
	/**
	 *       
	 * @author Administrator
	 *
	 */
	public interface OnLoadListener{
		void onLoad();
	}
	
	/**
	 *       
	 */
	public void loadComplete(){
		footerView.setVisibility(View.GONE);
		isLoading = false;
		this.invalidate();
	}

}
</span>

下部ドロップダウンレイアウトfooter.xml
<span style="font-family:KaiTi_GB2312;font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/footer_ll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal" >

    <ProgressBar
        android:id="@+id/progress"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:layout_marginTop="30dp" />

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:text="    ..."
        android:textColor="#FF0000" />

</LinearLayout></span>

二.ListViewトップドロップダウン・リフレッシュ
データ上部ドロップダウン・リフレッシュの手順は、次のとおりです.
1.上部のカスタムビューをロードし、ビューの余白を設定してビューを表示および非表示にします.
2.OnScrollListenerでイベントを傍受し、ListViewのアクティブ状態とfirstVisibleItemのトップに表示されるItemを取得する.
3.OnTouchListenerによるイベントの傍受、トップであるか否かの判断、およびACTION_の処理DOWN,ACTION_MOVE,ACTION_UP
各ステータスイベントは、none(通常)、pull(ドロップダウン)、release(リリース)、refashing(リフレッシュ)などのステータスを記録します.
ACTION_DOWN:最初の列にあるかどうかを判断し、もし、その点位置startYを記録する.
ACTION_MOVE:移動後のtempYを記録し,ピッチspaceを取得し,Viewの高さと比較した後,動的にView上辺ピッチを取得し,設定する.
ACTION_UP:refashing状態として記録し、データを更新する
4.リフレッシュが完了したら、それぞれの状態を復元し、Viewを非表示にします.
上部ドロップダウンでカスタムReflashListViewをリフレッシュ
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.example.paginationrefreshlistdemo.listview;

import java.text.SimpleDateFormat;
import java.util.Date;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.RotateAnimation;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;
import com.example.paginationrefreshlistdemo.R;

public class RefreshListView extends ListView implements OnScrollListener{
	//  View
	private View topView;
	//     View
	int firstVisibleItem;
	//  View   
	int headerHeight;
	// listview       ;
	int scrollState;
	//   ,    listview      ;
	boolean isRefresh;
	//     Y ;
	int startY;

	int state;//      ;
	final int NONE = 0;//     ;
	final int PULL = 1;//       ;
	final int RELESE = 2;//       ;
	final int REFLASHING = 3;//     ;
	
	public RefreshListView(Context context) {
		super(context);
		initView(context);
	}
	
	public RefreshListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
		
	}

	public RefreshListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView(context);
	}
	
	/**
	 *    ListView
	 */
	private void initView(Context context){
		LayoutInflater mInflater = LayoutInflater.from(context);
		topView = mInflater.inflate(R.layout.top, null);
		
		measureView(topView);
		headerHeight = topView.getMeasuredHeight();
		//        
		topPadding(-headerHeight);
		
		this.setOnScrollListener(this);
		this.addHeaderView(topView);
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		//      ,       not scrolling
		this.scrollState = scrollState;
	}
	
	/**
	 *      ,    , ;
	 * 
	 * @param view
	 */
	private void measureView(View view) {
		ViewGroup.LayoutParams p = view.getLayoutParams();
		if (p == null) {
			p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
					ViewGroup.LayoutParams.WRAP_CONTENT);
		}
		int width = ViewGroup.getChildMeasureSpec(0, 0, p.width);
		int height;
		int tempHeight = p.height;
		if (tempHeight > 0) {
			height = MeasureSpec.makeMeasureSpec(tempHeight,
					MeasureSpec.EXACTLY);
		} else {
			height = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
		}
		view.measure(width, height);
	}

	/**
	 *   header       ;
	 * 
	 * @param topPadding
	 */
	private void topPadding(int topPadding) {
		topView.setPadding(topView.getPaddingLeft(), topPadding,
				topView.getPaddingRight(), topView.getPaddingBottom());
		topView.invalidate();
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		this.firstVisibleItem = firstVisibleItem ;
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		// TODO Auto-generated method stub
		switch (ev.getAction()) {
		//  
		case MotionEvent.ACTION_DOWN:
			if (firstVisibleItem == 0) {
				isRefresh = true;
				startY = (int) ev.getY();
			}
			break;
		//  
		case MotionEvent.ACTION_MOVE:
			onMove(ev);
			break;
		//  
		case MotionEvent.ACTION_UP:
			if (state == RELESE) {
				state = REFLASHING;
				//       ;
				reflashViewByState();
				onRefreshListener.onRefresh();
			} else if (state == PULL) {
				state = NONE;
				isRefresh = false;
				reflashViewByState();
			}
			break;
		}
		return super.onTouchEvent(ev);
	}

	/**
	 *         ;
	 * 
	 * @param ev
	 */
	private void onMove(MotionEvent ev) {
		if (!isRefresh) {
			return;
		}
		int tempY = (int) ev.getY();
		int space = tempY - startY;
		int topPadding = space - headerHeight;
		switch (state) {
		case NONE:
			if (space > 0) {
				state = PULL;
				reflashViewByState();
			}
			break;
		case PULL:
			topPadding(topPadding);
			if (space > headerHeight + 30
					&& scrollState == SCROLL_STATE_TOUCH_SCROLL) {
				state = RELESE;
				reflashViewByState();
			}
			break;
		case RELESE:
			topPadding(topPadding);
			if (space < headerHeight + 30) {
				state = PULL;
				reflashViewByState();
			} else if (space <= 0) {
				state = NONE;
				isRefresh = false;
				reflashViewByState();
			}
			break;
		}
	}

	/**
	 *       ,      ;
	 */
	private void reflashViewByState() {
		TextView tip = (TextView) topView.findViewById(R.id.tip);
		ImageView arrow = (ImageView) topView.findViewById(R.id.arrow);
		ProgressBar progress = (ProgressBar) topView.findViewById(R.id.progress_refresh);
		RotateAnimation anim = new RotateAnimation(0, 180,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f);
		anim.setDuration(500);
		anim.setFillAfter(true);
		RotateAnimation anim1 = new RotateAnimation(180, 0,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f);
		anim1.setDuration(500);
		anim1.setFillAfter(true);
		switch (state) {
		case NONE:
			arrow.clearAnimation();
			topPadding(-headerHeight);
			break;

		case PULL:
			arrow.setVisibility(View.VISIBLE);
			progress.setVisibility(View.GONE);
			tip.setText("      !");
			arrow.clearAnimation();
			arrow.setAnimation(anim1);
			break;
		case RELESE:
			arrow.setVisibility(View.VISIBLE);
			progress.setVisibility(View.GONE);
			tip.setText("      !");
			arrow.clearAnimation();
			arrow.setAnimation(anim);
			break;
		case REFLASHING:
			topPadding(50);
			arrow.setVisibility(View.GONE);
			progress.setVisibility(View.VISIBLE);
			tip.setText("    ...");
			arrow.clearAnimation();
			break;
		}
	}
	
	private OnRefreshListener onRefreshListener;
	public void setOnRefreshListener(OnRefreshListener onRefreshListener){
		this.onRefreshListener = onRefreshListener;
	}
	
	/**
	 *       
	 * @author Administrator
	 *
	 */
	public interface OnRefreshListener{
		void onRefresh();
	}
	
	/**
	 *       
	 */
	@SuppressLint("SimpleDateFormat")
	public void refreshComplete(){
		state = NONE;
		isRefresh = false;
		reflashViewByState();
		TextView lastupdatetime = (TextView) topView
				.findViewById(R.id.lastupdate_time);
		SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd  hh:mm:ss");
		Date date = new Date(System.currentTimeMillis());
		String time = format.format(date);
		lastupdatetime.setText(time);
	}

}
</span>

上部ドロップダウンはレイアウトtopをリフレッシュする.xml
<span style="font-family:KaiTi_GB2312;font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="10dip"
        android:paddingTop="10dip" >

        <LinearLayout
            android:id="@+id/layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="      !" />

            <TextView
                android:id="@+id/lastupdate_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <ImageView
            android:id="@+id/arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/layout"
            android:layout_marginRight="20dip"
            android:src="@drawable/pull" />

        <ProgressBar
            android:id="@+id/progress_refresh"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/layout"
            android:layout_marginRight="20dip"
            android:visibility="gone" />
    </RelativeLayout>

</LinearLayout></span>

三.その他のファイルコード
1.メインレイアウトactivity_main.xml
<span style="font-family:KaiTi_GB2312;font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
   >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="ListView             " 
        android:gravity="center"
        android:textSize="18sp"
        android:textColor="#FF0000"
        android:layout_marginBottom="20dp"
    	android:layout_marginTop="20dp"/>
    
    <ListView 
        android:id="@+id/main_lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ></ListView>

</LinearLayout>
</span>

2.下部ページングレイアウトactivity_pagination.xml
<span style="font-family:KaiTi_GB2312;font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
   >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="ListView      " 
        android:gravity="center"
        android:textSize="18sp"
        android:textColor="#FF0000"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"/>
    
    <com.example.paginationrefreshlistdemo.listview.PaginationListView 
        android:id="@+id/pagination_lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</LinearLayout>
</span>

3.上部ドロップダウン・リフレッシュactivity_refresh.xml
<span style="font-family:KaiTi_GB2312;font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
   >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="ListView      " 
        android:gravity="center"
        android:textSize="18sp"
        android:textColor="#FF0000"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"/>
    
    <com.example.paginationrefreshlistdemo.listview.PaginationListView 
        android:id="@+id/pagination_lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</LinearLayout>
</span>

4.Adapterロードレイアウトlist_view.xml
<span style="font-family:KaiTi_GB2312;font-size:18px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/content_ll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginLeft="20dp"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/content_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="  ,   "
            android:textColor="#FF0000" />

        <TextView
            android:id="@+id/date_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#00FF00" />
    </LinearLayout>

    <ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@id/content_ll"
        android:src="@drawable/emotion" />

</RelativeLayout></span>

5.エンティティApkBean
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.example.paginationrefreshlistdemo.bean;

public class ApkBean {
	private String content;
	private String dateString;
	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}
	/**
	 * @param content the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}
	/**
	 * @return the dateString
	 */
	public String getDateString() {
		return dateString;
	}
	/**
	 * @param dateString the dateString to set
	 */
	public void setDateString(String dateString) {
		this.dateString = dateString;
	}
	
}
</span>

6.アダプターDemoAdapter
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.example.paginationrefreshlistdemo.adapter;

import java.util.List;

import com.example.paginationrefreshlistdemo.R;
import com.example.paginationrefreshlistdemo.bean.ApkBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DemoAdapter extends BaseAdapter {
	private List<ApkBean> datas ;
	private LayoutInflater mInfalter;
	
	public DemoAdapter(Context context,List<ApkBean> datas){
		this.datas = datas;
		this.mInfalter = LayoutInflater.from(context);
	}
	
	public void updateView( List<ApkBean> datas ){
		this.datas = datas;
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		HolderView holderView;
		
		if(convertView == null){
			holderView = new HolderView();
			convertView = mInfalter.inflate(R.layout.list_view_main, null);
			holderView.contentTv = (TextView) convertView.findViewById(R.id.content_tv);
			holderView.dateTv = (TextView) convertView.findViewById(R.id.date_tv);
			convertView.setTag(holderView);
			
		}else{
			holderView =(HolderView) convertView.getTag();
		}
		holderView.contentTv.setText(datas.get(position).getContent());
		if(datas.get(position).getDateString() == null){
			holderView.dateTv.setVisibility(View.GONE);
		}else{
			holderView.dateTv.setVisibility(View.VISIBLE);
			holderView.dateTv.setText(datas.get(position).getDateString());
		}
		return convertView;
	}
	
	public class HolderView{
		ImageView iv;
		TextView contentTv,dateTv;
	}

}
</span>

7.主関数MainActivity.JAvaは、ListViewに下部ドロップダウンロードと上部ドロップダウンリフレッシュデータが含まれています.
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.example.paginationrefreshlistdemo.activity;

import java.util.ArrayList;
import java.util.List;

import com.example.paginationrefreshlistdemo.R;
import com.example.paginationrefreshlistdemo.adapter.DemoAdapter;
import com.example.paginationrefreshlistdemo.bean.ApkBean;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MainActivity extends Activity {

	private ListView mainLv;
	private DemoAdapter demoAdapter;
	private List<ApkBean> datas = new ArrayList<ApkBean>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initData();
		mainLv =(ListView) this.findViewById(R.id.main_lv);
		
		mainLv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				switch (position) {
				case 0:
					startActvity(PaginationActivity.class);
					break;

				case 1:
					startActvity(RefreshActivity.class);
					break;
				}
			}
		});
		
		showView();
	}
	
	private void startActvity(Class<?> clz){
		Intent intent = new Intent();
		intent.setClass(this, clz);
		this.startActivity(intent);
	}
	
	private void initData(){
		ApkBean apkBean = new ApkBean();
		apkBean.setContent("ListView    ");
		
		ApkBean apkBean2 = new ApkBean();
		apkBean2.setContent("ListView    ");
		datas.add(apkBean);
		datas.add(apkBean2);
	}
	
	private void showView(){
		if(demoAdapter == null){
			demoAdapter = new DemoAdapter(this, datas);
			mainLv.setAdapter(demoAdapter);
		}else{
			demoAdapter.updateView(datas);
		}
	}
	
}
</span>

8.ページングロードPaginationActivity.JAva、PaginationListViewを使用
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.example.paginationrefreshlistdemo.activity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.example.paginationrefreshlistdemo.R;
import com.example.paginationrefreshlistdemo.adapter.DemoAdapter;
import com.example.paginationrefreshlistdemo.bean.ApkBean;
import com.example.paginationrefreshlistdemo.listview.PaginationListView;
import com.example.paginationrefreshlistdemo.listview.PaginationListView.OnLoadListener;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class PaginationActivity extends Activity implements OnLoadListener {

	private PaginationListView paginationLv;
	private DemoAdapter paginationAdapter;
	private List<ApkBean> datas = new ArrayList<ApkBean>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pagination);
		initData();
		paginationLv = (PaginationListView) this
				.findViewById(R.id.pagination_lv);
		paginationLv.setOnLoadListener(this);

		paginationLv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

			}
		});

		showView();
	}

	@SuppressLint("SimpleDateFormat")
	private void initData() {
		ApkBean apkBean;
		String dateString;
		long dateLong = new Date().getTime();
		for (int i = 0; i < 20; i++) {
			apkBean = new ApkBean();
			apkBean.setContent("             " + i);
			dateLong = dateLong + i * 1000 * 6;
			dateString = new SimpleDateFormat("yyyy-MM-dd HHmmss")
					.format(new Date(dateLong));
			apkBean.setDateString(dateString);
			datas.add(apkBean);
		}
	}

	/**
	 *      
	 */
	private void showView() {
		if (paginationAdapter == null) {
			paginationAdapter = new DemoAdapter(this, datas);
			paginationLv.setAdapter(paginationAdapter);
		} else {
			paginationAdapter.updateView(datas);
		}
	}

	@Override
	public void onLoad() {
		//       ,      
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				initLoadData();
				showView();
				paginationLv.loadComplete();
			}
		}, 3000);
	}

	@SuppressLint("SimpleDateFormat")
	private void initLoadData() {
		ApkBean apkBean;
		String dateString;
		long dateLong = new Date().getTime();
		for (int i = 0; i < 20; i++) {
			apkBean = new ApkBean();
			apkBean.setContent("            " + i);
			dateLong = dateLong + i * 1000 * 6 * 60;
			dateString = new SimpleDateFormat("yyyy-MM-dd HHmmss")
					.format(new Date(dateLong));
			apkBean.setDateString(dateString);
			datas.add(apkBean);
		}
	}

}
</span>

9.上部リフレッシュRefreshActivity.JAva、カスタムRefreshListViewを使用
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.example.paginationrefreshlistdemo.activity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.example.paginationrefreshlistdemo.R;
import com.example.paginationrefreshlistdemo.adapter.DemoAdapter;
import com.example.paginationrefreshlistdemo.bean.ApkBean;
import com.example.paginationrefreshlistdemo.listview.RefreshListView;
import com.example.paginationrefreshlistdemo.listview.RefreshListView.OnRefreshListener;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class RefreshActivity extends Activity implements OnRefreshListener{

	private RefreshListView refreshLv;
	private DemoAdapter refreshAdapter;
	private List<ApkBean> datas = new ArrayList<ApkBean>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_refresh);
		initData();
		refreshLv =(RefreshListView) this.findViewById(R.id.refresh_lv);
		refreshLv.setOnRefreshListener(this);
		refreshLv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				
			}
		});
		
		showView();
	}
	
	@SuppressLint("SimpleDateFormat")
	private void initData(){
		ApkBean apkBean;
		String dateString;
		long dateLong = new Date().getTime();
		for (int i = 0; i < 20; i++) {
			apkBean = new ApkBean();
			apkBean.setContent("               " + i);
			dateLong = dateLong + i * 1000 * 6;
			dateString = new SimpleDateFormat("yyyy-MM-dd HHmmss")
					.format(new Date(dateLong));
			apkBean.setDateString(dateString);
			datas.add(apkBean);
		}
	}
	
	private void showView(){
		if(refreshAdapter == null){
			refreshAdapter = new DemoAdapter(this, datas);
			refreshLv.setAdapter(refreshAdapter);
		}else{
			refreshAdapter.updateView(datas);
		}
	}

	@Override
	public void onRefresh() {
		new Handler().postDelayed(new Runnable() {
			
			@Override
			public void run() {
				initLoadData();
				refreshAdapter.updateView(datas);
				refreshLv.refreshComplete();
			}
		}, 3000);
	}
	
	@SuppressLint("SimpleDateFormat")
	private void initLoadData() {
		ApkBean apkBean;
		String dateString;
		long dateLong = new Date().getTime();
		for (int i = 0; i < 5; i++) {
			apkBean = new ApkBean();
			apkBean.setContent("         " + i);
			dateLong = dateLong + i * 1000 * 6 * 60;
			dateString = new SimpleDateFormat("yyyy-MM-dd HHmmss")
					.format(new Date(dateLong));
			apkBean.setDateString(dateString);
			datas.add(apkBean);
		}
	}
	
}
</span>

以上が本稿のすべての内容です.
ソースのダウンロードアドレス:http://download.csdn.net/detail/a123demi/8147253