自定义封装上拉加载下拉刷新ListVIew

public class PullToRefreshListView extends PullToRefreshAdapterViewBase<ListView> {

    class InternalListView extends ListView implements EmptyViewMethodAccessor {

        public InternalListView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        @Override
        public void setEmptyView(View emptyView) {
            PullToRefreshListView.this.setEmptyView(emptyView);
        }

        @Override
        public void setEmptyViewInternal(View emptyView) {
            super.setEmptyView(emptyView);
        }

        public ContextMenuInfo getContextMenuInfo() {
            return super.getContextMenuInfo();
        }
    }

    public PullToRefreshListView(Context context) {
        super(context);
        this.setDisableScrollingWhileRefreshing(false);
    }

    public PullToRefreshListView(Context context, int mode) {
        super(context, mode);
        this.setDisableScrollingWhileRefreshing(false);
    }

    public PullToRefreshListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setDisableScrollingWhileRefreshing(false);
    }

    @Override
    public ContextMenuInfo getContextMenuInfo() {
        return ((InternalListView) getRefreshableView()).getContextMenuInfo();
    }

}
 
用法XML代码:
<com.fox.exercise.view.PullToRefreshListView
  xmlns:ptr="http://schemas.android.com/apk/res/com.fox.exercise"
  android:id="@+id/activity_list"
  android:layout_width="match_parent"
  android:layout_height="fill_parent"
  android:cacheColorHint="#00000000"
  ptr:mode="both"/>
Java代码:
public static final int MODE_PULL_DOWN_TO_REFRESH = 0x1;
public static final int MODE_DEFAULT_LOAD = 0x2;
PullToRefreshListView actiondetailListView = (PullToRefreshListView) findViewById(R.id.activity_list);
actiondetailListView.setOnRefreshListener(new OnRefreshListener() {
@Override public void onRefresh(int pullDirection) {
	if (mSportsApp.isOpenNetwork()) {            	
		switch (pullDirection) {                
		case FansAndNear.MODE_DEFAULT_LOAD://这两数据自己定义                    
			times++;                    
			GetActionData();//加载数据方法                    
			break;                
		case FansAndNear.MODE_PULL_DOWN_TO_REFRESH:                   
			times = 0;                    
			GetActionData();//加载数据方法                    
			break;            }        
			} else {            
			Toast.makeText(ActivityInfoWebView.this, getResources().getString(R.string.acess_server_error), Toast.LENGTH_SHORT).show();
			ctiondetailListView.onRefreshComplete(); 
			}}});


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值