Listview
public final class PullToRefreshListActivity extends ListActivity {
private LinkedList<String> mListItems;private PullToRefreshListView mPullRefreshListView;private ArrayAdapter<String> mAdapter;private String[] mStrings = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "包青天", "1", "2", "3", "4", "5", "6", "7", "8", "9", "包青天" };@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_list);mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {@Overridepublic void onRefresh(PullToRefreshBase<ListView> refreshView) {//日期格式String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME| DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);// 更新最后刷新时间refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);// Do work to refresh the list here.new GetDataTask().execute();}});// Add an end-of-list listenermPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() {@Overridepublic void onLastItemVisible() {Toast.makeText(PullToRefreshListActivity.this, "滑到了最后一条", Toast.LENGTH_SHORT).show();}});//获取真正的ListViewListView actualListView = mPullRefreshListView.getRefreshableView();// Need to use the Actual ListView when registering for Context MenuregisterForContextMenu(actualListView);mListItems = new LinkedList<String>();mListItems.addAll(Arrays.asList(mStrings));mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);//添加声音事件SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>(this);soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event);soundListener.addSoundEvent(State.RESET, R.raw.reset_sound);soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound);mPullRefreshListView.setOnPullEventListener(soundListener);// You can also just use setListAdapter(mAdapter) or mPullRefreshListView.setAdapter(mAdapter)actualListView.setAdapter(mAdapter);}//**************************************************************************************************************************private class GetDataTask extends AsyncTask<Void, Void, String[]> {@Overrideprotected String[] doInBackground(Void... params) {// Simulates a background job.try {Thread.sleep(1000);} catch (InterruptedException e) {}return mStrings;}@Overrideprotected void onPostExecute(String[] result) {mListItems.addFirst("Added after refresh...");mAdapter.notifyDataSetChanged();// Call onRefreshComplete when the list has been refreshed.mPullRefreshListView.onRefreshComplete();super.onPostExecute(result);}}}activity_ptr_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><com.handmark.pulltorefresh.library.PullToRefreshListViewandroid:id="@+id/pull_refresh_list"android:layout_width="fill_parent"android:layout_height="fill_parent"android:cacheColorHint="#00000000"android:divider="#19000000"android:dividerHeight="4dp"android:fadingEdge="none"android:fastScrollEnabled="false"android:footerDividersEnabled="false"android:headerDividersEnabled="false"android:smoothScrollbar="true" /></LinearLayout>
GridView
public final class GridViewActivity extends Activity {
private LinkedList<String> mListItems;private PullToRefreshGridView mPullRefreshGridView;private GridView mGridView;private ArrayAdapter<String> mAdapter;private boolean isLast;//true对应onPullUpToRefresh,代表拉到【最后】时【从下往上】拉@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_grid);mPullRefreshGridView = (PullToRefreshGridView) findViewById(R.id.pull_refresh_grid);mGridView = mPullRefreshGridView.getRefreshableView();mPullRefreshGridView.setOnRefreshListener(new OnRefreshListener2<GridView>() {@Overridepublic void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {Toast.makeText(GridViewActivity.this, "下拉!", Toast.LENGTH_SHORT).show();isLast = false;new GetDataTask().execute();}@Overridepublic void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {Toast.makeText(GridViewActivity.this, "上拉!", Toast.LENGTH_SHORT).show();isLast = true;new GetDataTask().execute();}});mListItems = new LinkedList<String>();TextView tv = new TextView(this);tv.setGravity(Gravity.CENTER);tv.setText("下拉或上拉添加条目");mPullRefreshGridView.setEmptyView(tv);mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);mGridView.setAdapter(mAdapter);}private class GetDataTask extends AsyncTask<Void, Void, Void> {@Overrideprotected Void doInBackground(Void... params) {try {Thread.sleep(1000);} catch (InterruptedException e) {}return null;}@Overrideprotected void onPostExecute(Void result) {if (isLast) {mListItems.addLast("新增条目");} else {String[] mStrings = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };mListItems.addAll(Arrays.asList(mStrings));}mAdapter.notifyDataSetChanged();mPullRefreshGridView.onRefreshComplete();super.onPostExecute(result);}}}activity_ptr_grid.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><com.handmark.pulltorefresh.library.PullToRefreshGridViewxmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/pull_refresh_grid"android:layout_width="fill_parent"android:layout_height="fill_parent"android:columnWidth="100dp"android:gravity="fill"android:horizontalSpacing="1dp"android:numColumns="auto_fit"android:stretchMode="columnWidth"android:verticalSpacing="1dp"ptr:ptrDrawable="@drawable/android"ptr:ptrMode="both" /></LinearLayout>
ViewPage
public class ViewPagerActivity extends Activity implements OnRefreshListener2<ViewPager> {
private PullToRefreshViewPager mPullToRefreshViewPager;//封装过的带刷新功能的ViewPagerprivate ViewPager viewPager;//代表原始的ViewPager,某些API若PullToRefreshViewPager没有提供就找原始的ViewPagerprivate MyPagerAdapter mAdapter;private LinkedList<Integer> mListItems;//ViewPager的Adapter中封装的数据,封装的都是图片的idprivate boolean isLast;//true对应onPullUpToRefresh,代表拉到【最后】时【从右往左】拉@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_viewpager);mListItems = new LinkedList<Integer>();mListItems.add(R.drawable.wallpaper);mListItems.add(R.drawable.wallpaper);mListItems.add(R.drawable.wallpaper);mPullToRefreshViewPager = (PullToRefreshViewPager) findViewById(R.id.pull_refresh_viewpager);mPullToRefreshViewPager.setOnRefreshListener(this);viewPager = mPullToRefreshViewPager.getRefreshableView();mAdapter = new MyPagerAdapter();viewPager.setAdapter(mAdapter);}@Overridepublic void onPullDownToRefresh(PullToRefreshBase<ViewPager> refreshView) {isLast = false;new GetDataTask().execute();}@Overridepublic void onPullUpToRefresh(PullToRefreshBase<ViewPager> refreshView) {isLast = true;new GetDataTask().execute();}//************************************************************************************************************private class MyPagerAdapter extends PagerAdapter {@Overridepublic View instantiateItem(ViewGroup container, int position) {ImageView imageView = new ImageView(container.getContext());imageView.setImageResource(mListItems.get(position));container.addView(imageView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);return imageView;}@Overridepublic int getCount() {return mListItems.size();}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {container.removeView((View) object);}@Overridepublic boolean isViewFromObject(View view, Object object) {return view == object;}}//************************************************************************************************************private class GetDataTask extends AsyncTask<Void, Void, Void> {@Overrideprotected Void doInBackground(Void... params) {try {Thread.sleep(1000);} catch (InterruptedException e) {}return null;}@Overrideprotected void onPostExecute(Void result) {if (isLast) {mListItems.addLast(R.drawable.android);mAdapter.notifyDataSetChanged();viewPager.setCurrentItem(mListItems.size() - 1);//这里超出范围了也不报错,比如写成+10,估计是内部做了范围判断} else {mListItems.addFirst(R.drawable.icon);mAdapter.notifyDataSetChanged();viewPager.setAdapter(mAdapter);//卧槽,需要重新设置一下Adapter,以后遇到不能正常加载条目的情况都这么干,屡试不爽!viewPager.setCurrentItem(0);//这里超出范围同样也不报错,比如写成-10}mPullToRefreshViewPager.onRefreshComplete();super.onPostExecute(result);}}}activity_ptr_viewpager.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" ><com.handmark.pulltorefresh.extras.viewpager.PullToRefreshViewPagerxmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/pull_refresh_viewpager"android:layout_width="fill_parent"android:layout_height="fill_parent"ptr:ptrAnimationStyle="flip"ptr:ptrHeaderBackground="@android:color/darker_gray"ptr:ptrMode="both" /></FrameLayout>
ListView+Fragment
public final class ListView_Fragment extends FragmentActivity implements OnRefreshListener<ListView> {
private PullToRefreshListView mPullRefreshListView;private ArrayAdapter<String> mAdapter;//适配器private LinkedList<String> mListItems;//数据@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_list_fragment);PullToRefreshListFragment mPullRefreshListFragment = (PullToRefreshListFragment) getSupportFragmentManager().findFragmentById(R.id.frag_ptr_list);mPullRefreshListView = mPullRefreshListFragment.getPullToRefreshListView();mPullRefreshListView.setMode(Mode.BOTH);//OnRefreshListener也可以实现上下刷新mPullRefreshListView.setOnRefreshListener(this);String[] mStrings = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };mListItems = new LinkedList<String>();mListItems.addAll(Arrays.asList(mStrings));mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);ListView actualListView = mPullRefreshListView.getRefreshableView();//或使用getListView()actualListView.setAdapter(mAdapter);//也可直接用mPullRefreshListView设置mPullRefreshListFragment.setListShown(true);//是否显示内容,必须调用!不知道具体是啥玩意}@Overridepublic void onRefresh(PullToRefreshBase<ListView> refreshView) {new GetDataTask().execute();}private class GetDataTask extends AsyncTask<Void, Void, Void> {@Overrideprotected Void doInBackground(Void... params) {try {Thread.sleep(1000);} catch (InterruptedException e) {}return null;}@Overrideprotected void onPostExecute(Void result) {mListItems.addFirst("新增");mAdapter.notifyDataSetChanged();mPullRefreshListView.onRefreshComplete();super.onPostExecute(result);}}}activity_ptr_list_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><fragmentandroid:id="@+id/frag_ptr_list"android:name="com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment"android:layout_width="match_parent"android:layout_height="match_parent" /></FrameLayout>
ViewPage+ListView
// 下拉(从上往下拉)在最上面添加数据,上拉在最下面添加数据,[左拉向右边添加数据,右拉向左边添加数据]
public class ViewPage_ListView extends Activity implements OnRefreshListener2<ListView> {private Context context = ViewPage_ListView.this;private ViewPager mViewPager;//用的是原生的ViewPagerprivate MyPagerAdapter mPagerAdapter;//ViewPager的适配器private LinkedList<LinkedList<String>> mPagerItems = new LinkedList<LinkedList<String>>();//ViewPager中的封装的数据private LinkedList<String> mListItems0 = new LinkedList<String>();//ViewPager中第0个ListView的数据private LinkedList<String> mListItems1 = new LinkedList<String>();//ViewPager中第1个ListView的数据private LinkedList<String> mListItems2 = new LinkedList<String>();//ViewPager中第2个ListView的数据private LinkedList<String> mListItems3 = new LinkedList<String>();//ViewPager中第3个ListView的数据private LinkedList<ArrayAdapter<String>> mListAdapters = new LinkedList<ArrayAdapter<String>>();//封装ListView的适配器private ArrayAdapter<String> mListAdapter0;//第0个ListView的适配器private ArrayAdapter<String> mListAdapter1;//第1个ListView的适配器private ArrayAdapter<String> mListAdapter2;//第2个ListView的适配器private ArrayAdapter<String> mListAdapter3;//第3个ListView的适配器private PullToRefreshBase<ListView> currentPTRefreshView;//代表当前条目的ListViewprivate boolean isLast;//true对应onPullUpToRefresh,代表拉到【最后】时【从下往上】拉@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_list_in_vp);//初始化ViewPager中的封装的数据mListItems0.addAll(Arrays.asList(new String[] { "0", "0", "0", "0", "0", "0", "0", "0", "0" }));mListItems1.addAll(Arrays.asList(new String[] { "1", "1", "1", "1", "1", "1", "1", "1", "1" }));mListItems2.addAll(Arrays.asList(new String[] { "2", "2", "2", "2", "2", "2", "2", "2", "2" }));mListItems3.addAll(Arrays.asList(new String[] { "3", "3", "3", "3", "3", "3", "3", "3", "3" }));mPagerItems.add(mListItems0);mPagerItems.add(mListItems1);mPagerItems.add(mListItems2);mPagerItems.add(mListItems3);//初始化ListView的适配器mListAdapter0 = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, mListItems0);mListAdapter1 = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, mListItems1);mListAdapter2 = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, mListItems2);mListAdapter3 = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, mListItems3);//将ListView的适配器封装到一个集合中mListAdapters.add(mListAdapter0);mListAdapters.add(mListAdapter1);mListAdapters.add(mListAdapter2);mListAdapters.add(mListAdapter3);mViewPager = (ViewPager) findViewById(R.id.vp_list);mPagerAdapter = new MyPagerAdapter();mViewPager.setAdapter(mPagerAdapter);}@Overridepublic void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {this.currentPTRefreshView = refreshView;//标识你刷新的是哪个ListViewthis.isLast = false;new GetDataTask().execute();}@Overridepublic void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {this.currentPTRefreshView = refreshView;this.isLast = true;new GetDataTask().execute();}//**************************************************************************************************************************private class MyPagerAdapter extends PagerAdapter {@Overridepublic View instantiateItem(ViewGroup container, int position) {//初始化ViewPager中的View,此View是一个PullToRefreshListViewPullToRefreshListView mListView = (PullToRefreshListView) LayoutInflater.from(context).inflate(R.layout.layout_listview_in_viewpager,container, false);//ListView的适配器mListView.setAdapter(mListAdapters.get(position));mListView.setOnRefreshListener(ViewPage_ListView.this);//将要显示的条目加入到ViewGroup的缓存容器中,然后作为返回值返回container.addView(mListView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);return mListView;}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {container.removeView((View) object);}@Overridepublic boolean isViewFromObject(View view, Object object) {return view == object;}@Overridepublic int getCount() {return mPagerItems.size();}}//**************************************************************************************************************************private class GetDataTask extends AsyncTask<Void, Void, Void> {@Overrideprotected Void doInBackground(Void... params) {try {Thread.sleep(1000);} catch (InterruptedException e) {}return null;}@Overrideprotected void onPostExecute(Void result) {int position = mViewPager.getCurrentItem();//ViewPager当前的条目if (isLast) {switch (position) {case 0:for (int i = 0; i < 1; i++) {mPagerItems.get(position).addLast("现在是ViewPager第0个条目");mPagerItems.get(position).addLast("上拉时在最后新增一条数据");}break;case 1:for (int i = 0; i < 1; i++) {mPagerItems.get(position).addLast("现在是ViewPager第1个条目");mPagerItems.get(position).addLast("上拉时在最后新增一条数据");}break;case 2:for (int i = 0; i < 1; i++) {mPagerItems.get(position).addLast("现在是ViewPager第2个条目");mPagerItems.get(position).addLast("上拉时在最后新增一条数据");}break;case 3:for (int i = 0; i < 1; i++) {mPagerItems.get(position).addLast("现在是ViewPager第3个条目");mPagerItems.get(position).addLast("上拉时在最后新增一条数据");}break;}} else {mPagerItems.get(position).addFirst("现在是ViewPager第" + position + "个条目");mPagerItems.get(position).addFirst("下拉时在最前新增一条数据");}mListAdapters.get(position).notifyDataSetChanged();mPagerAdapter.notifyDataSetChanged();currentPTRefreshView.onRefreshComplete();super.onPostExecute(result);}}}activity_ptr_list_in_vp.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><android.support.v4.view.ViewPagerandroid:id="@+id/vp_list"android:layout_width="fill_parent"android:layout_height="fill_parent" /></LinearLayout>layout_listview_in_viewpager.xml
<?xml version="1.0" encoding="utf-8"?>
<com.handmark.pulltorefresh.library.PullToRefreshListView xmlns:android="http://schemas.android.com/apk/res/android"xmlns:ptr="http://schemas.android.com/apk/res-auto"android:layout_width="fill_parent"android:layout_height="fill_parent"ptr:ptrMode="both" />
ScrollView
public final class ScrollViewActivity extends Activity {
PullToRefreshScrollView mPullRefreshScrollView;ScrollView mScrollView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_scrollview);mPullRefreshScrollView = (PullToRefreshScrollView) findViewById(R.id.pull_refresh_scrollview);mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener<ScrollView>() {@Overridepublic void onRefresh(PullToRefreshBase<ScrollView> refreshView) {new GetDataTask().execute();}});mScrollView = mPullRefreshScrollView.getRefreshableView();}private class GetDataTask extends AsyncTask<Void, Void, String[]> {@Overrideprotected String[] doInBackground(Void... params) {try {Thread.sleep(1000);} catch (InterruptedException e) {}return null;}@Overrideprotected void onPostExecute(String[] result) {mPullRefreshScrollView.onRefreshComplete();super.onPostExecute(result);}}}activity_ptr_scrollview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><com.handmark.pulltorefresh.library.PullToRefreshScrollViewxmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/pull_refresh_scrollview"android:layout_width="fill_parent"android:layout_height="fill_parent"ptr:ptrAnimationStyle="flip"ptr:ptrMode="both" ><TextViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:padding="8dp"android:text="@string/filler_text"android:textSize="16sp" /></com.handmark.pulltorefresh.library.PullToRefreshScrollView></LinearLayout>
水平的ScrollView
public final class Horizontal_ScrollView extends Activity {
PullToRefreshHorizontalScrollView mPullRefreshScrollView;HorizontalScrollView mScrollView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_horizontalscrollview);mPullRefreshScrollView = (PullToRefreshHorizontalScrollView) findViewById(R.id.pull_refresh_horizontalscrollview);mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener<HorizontalScrollView>() {@Overridepublic void onRefresh(PullToRefreshBase<HorizontalScrollView> refreshView) {new GetDataTask().execute();}});mScrollView = mPullRefreshScrollView.getRefreshableView();}private class GetDataTask extends AsyncTask<Void, Void, String[]> {@Overrideprotected String[] doInBackground(Void... params) {try {Thread.sleep(1000);} catch (InterruptedException e) {}return null;}@Overrideprotected void onPostExecute(String[] result) {mPullRefreshScrollView.onRefreshComplete();super.onPostExecute(result);}}}activity_ptr_horizontalscrollview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollViewxmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/pull_refresh_horizontalscrollview"android:layout_width="fill_parent"android:layout_height="fill_parent"ptr:ptrAnimationStyle="flip"ptr:ptrMode="both" ><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="fill_parent"android:orientation="horizontal" ><TextViewstyle="@style/HorizScrollViewItem"android:layout_width="wrap_content"android:layout_height="fill_parent"android:background="#ff99cc00" /><TextViewstyle="@style/HorizScrollViewItem"android:layout_width="wrap_content"android:layout_height="fill_parent"android:background="#ff33b5e5" /><TextViewstyle="@style/HorizScrollViewItem"android:layout_width="wrap_content"android:layout_height="fill_parent"android:background="#ffcc0000" /><TextViewstyle="@style/HorizScrollViewItem"android:layout_width="wrap_content"android:layout_height="fill_parent"android:background="#ff669900" /></LinearLayout></com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView></LinearLayout>styles 样式
<?xml version="1.0" encoding="utf-8"?><resources xmlns:android="http://schemas.android.com/apk/res/android"><style name="HorizScrollViewItem"><item name="android:paddingRight">50dp</item><item name="android:paddingLeft">50dp</item><item name="android:gravity">center</item><item name="android:textAppearance">?android:attr/textAppearanceMedium</item><item name="android:text">Sample Item</item></style></resources>
WebView
public final class WebViewActivity extends Activity {
PullToRefreshWebView mPullRefreshWebView;WebView mWebView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ptr_webview);mPullRefreshWebView = (PullToRefreshWebView) findViewById(R.id.pull_refresh_webview);mWebView = mPullRefreshWebView.getRefreshableView();mWebView.getSettings().setJavaScriptEnabled(true);mWebView.setWebViewClient(new SampleWebViewClient());mWebView.loadUrl("http://news.sina.com.cn/");}private static class SampleWebViewClient extends WebViewClient {@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {view.loadUrl(url);return true;}}}activity_ptr_webview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent" ><com.handmark.pulltorefresh.library.PullToRefreshWebViewxmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/pull_refresh_webview"android:layout_height="fill_parent"android:layout_width="fill_parent"ptr:ptrMode="both" /></LinearLayout>