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();
}}});