自修改Pushtorefresh,实现上下均可刷新

原来的滑动刷新仅仅是top滑动刷新,按照逻辑只是加载最新的列表,但是下面列表你不可能一次显示,可以用加载第二页的形式加载。上图如下:
1.png 



2.png 

3.png 


   list不再是简单的title列表,在此是自定义的RatingAdapter,直接抠的eoe出的android开发权威指南里面的adapter,当然你也可以自己定义。。

基本修改如下:

注意没有修改成view,只是在原来的view里面加上:


  1.   private void init(Context context) {
  2.         // Load all of the animations we need in code rather than through XML
  3.         mFlipAnimation = new RotateAnimation(0, -180,
  4.                 RotateAnimation.RELATIVE_TO_SELF, 0.5f,
  5.                 RotateAnimation.RELATIVE_TO_SELF, 0.5f);
  6.         mFlipAnimation.setInterpolator(new LinearInterpolator());
  7.         mFlipAnimation.setDuration(250);
  8.         mFlipAnimation.setFillAfter(true);
  9.         mReverseFlipAnimation = new RotateAnimation(-180, 0,
  10.                 RotateAnimation.RELATIVE_TO_SELF, 0.5f,
  11.                 RotateAnimation.RELATIVE_TO_SELF, 0.5f);
  12.         mReverseFlipAnimation.setInterpolator(new LinearInterpolator());
  13.         mReverseFlipAnimation.setDuration(250);
  14.         mReverseFlipAnimation.setFillAfter(true);

  15.         mInflater = (LayoutInflater) context.getSystemService(
  16.                 Context.LAYOUT_INFLATER_SERVICE);

  17.                 mRefreshView = (RelativeLayout) mInflater.inflate(
  18.                                 R.layout.pull_to_refresh_header, this, false);
  19.         mRefreshViewText =
  20.             (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text);
  21.         mRefreshViewImage =
  22.             (ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image);
  23.         mRefreshViewProgress =
  24.             (ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress);
  25.         mRefreshViewLastUpdated =
  26.             (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_updated_at);

  27.         mRefreshViewImage.setMinimumHeight(50);
  28.         mRefreshView.setOnClickListener(new OnClickRefreshListener());
  29.         mRefreshOriginalTopPadding = mRefreshView.getPaddingTop();

  30.         mRefreshState = TAP_TO_REFRESH;

  31.         addHeaderView(mRefreshView);
  32.         layout = new LinearLayout(context);
  33.       progressBar = new ProgressBar(context);
  34.      
  35.         // 进度条显示位置
  36.         progressBar.setPadding(40, 0, 15, 0);
  37.         progressBar.setVisibility(View.INVISIBLE);
  38.         
  39.         // 把进度条加入到layout中
  40.         layout.addView(progressBar, mLayoutParams);
  41.         // 文本内容
  42.          textView = new TextView(context);
  43.         textView.setText("点击加载数据....");
  44.         textView.setGravity(Gravity.CENTER_VERTICAL);
  45.         // 把文本加入到layout中
  46.         layout.addView(textView, FFlayoutParams);
  47.         // 设置layout的重力方向,即对齐方式是
  48.         layout.setGravity(Gravity.RIGHT);
  49.         // 设置ListView的页脚layout
  50.      
  51.     
  52.     //    layout.setOnClickListener(new addNextListener());
  53.         addFooterView(layout);
  54.         super.setOnScrollListener(this);

  55.         measureView(mRefreshView);
  56.         mRefreshViewHeight = mRefreshView.getMeasuredHeight();
  57.     }
复制代码
红色部分是添加底部刷新布局。。
然后在activity里面引用:




  1. ((PullToRefreshListView) getListView()).layout.setOnClickListener(new OnClickListener() {
  2.                         
  3.                         public void onClick(View v) {
  4.                                 // TODO Auto-generated method stub
  5.                                   ((PullToRefreshListView) getListView()).progressBar.setVisibility(View.VISIBLE);
  6.                                   ((PullToRefreshListView) getListView()).textView.setText("加载中....");
  7.                                         new  Thread(new Runnable() {
  8.                                                 
  9.                                                 public void run() {
  10.                                                         // TODO Auto-generated method stub
  11.                                                         
  12.                                                         try {
  13.                                                                 Thread.sleep(2000);
  14.                                                         } catch (InterruptedException e) {
  15.                                                                 // TODO Auto-generated catch block
  16.                                                                 e.printStackTrace();
  17.                                                         }
  18.                                                         Message message=new Message();
  19.                                                         message.what=1;//有数据
  20.                                                         
  21.                                                         //message.what=0;  没有数据
  22.                                                         PushActivity.this.bottomHandler.sendMessage(message);
  23.                                                 }
  24.                                         }).start();
  25.                         
  26.                         
  27.                         }
  28.                 });
复制代码
源代码:   Push.rar (325.77 KB, 下载次数: 14) 
欢迎大家批评指正。。。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值