原来的滑动刷新仅仅是top滑动刷新,按照逻辑只是加载最新的列表,但是下面列表你不可能一次显示,可以用加载第二页的形式加载。上图如下:
list不再是简单的title列表,在此是自定义的RatingAdapter,直接抠的eoe出的android开发权威指南里面的adapter,当然你也可以自己定义。。
基本修改如下:
注意没有修改成view,只是在原来的view里面加上:
复制代码
红色部分是添加底部刷新布局。。
然后在activity里面引用:
复制代码
源代码:
Push.rar (325.77 KB, 下载次数: 14)
欢迎大家批评指正。。。。。
list不再是简单的title列表,在此是自定义的RatingAdapter,直接抠的eoe出的android开发权威指南里面的adapter,当然你也可以自己定义。。
基本修改如下:
注意没有修改成view,只是在原来的view里面加上:
- private void init(Context context) {
- // Load all of the animations we need in code rather than through XML
- mFlipAnimation = new RotateAnimation(0, -180,
- RotateAnimation.RELATIVE_TO_SELF, 0.5f,
- RotateAnimation.RELATIVE_TO_SELF, 0.5f);
- mFlipAnimation.setInterpolator(new LinearInterpolator());
- mFlipAnimation.setDuration(250);
- mFlipAnimation.setFillAfter(true);
- mReverseFlipAnimation = new RotateAnimation(-180, 0,
- RotateAnimation.RELATIVE_TO_SELF, 0.5f,
- RotateAnimation.RELATIVE_TO_SELF, 0.5f);
- mReverseFlipAnimation.setInterpolator(new LinearInterpolator());
- mReverseFlipAnimation.setDuration(250);
- mReverseFlipAnimation.setFillAfter(true);
-
- mInflater = (LayoutInflater) context.getSystemService(
- Context.LAYOUT_INFLATER_SERVICE);
-
- mRefreshView = (RelativeLayout) mInflater.inflate(
- R.layout.pull_to_refresh_header, this, false);
- mRefreshViewText =
- (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text);
- mRefreshViewImage =
- (ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image);
- mRefreshViewProgress =
- (ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress);
- mRefreshViewLastUpdated =
- (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_updated_at);
-
- mRefreshViewImage.setMinimumHeight(50);
- mRefreshView.setOnClickListener(new OnClickRefreshListener());
- mRefreshOriginalTopPadding = mRefreshView.getPaddingTop();
-
- mRefreshState = TAP_TO_REFRESH;
-
- addHeaderView(mRefreshView);
- layout = new LinearLayout(context);
- progressBar = new ProgressBar(context);
-
- // 进度条显示位置
- progressBar.setPadding(40, 0, 15, 0);
- progressBar.setVisibility(View.INVISIBLE);
-
- // 把进度条加入到layout中
- layout.addView(progressBar, mLayoutParams);
- // 文本内容
- textView = new TextView(context);
- textView.setText("点击加载数据....");
- textView.setGravity(Gravity.CENTER_VERTICAL);
- // 把文本加入到layout中
- layout.addView(textView, FFlayoutParams);
- // 设置layout的重力方向,即对齐方式是
- layout.setGravity(Gravity.RIGHT);
- // 设置ListView的页脚layout
-
-
- // layout.setOnClickListener(new addNextListener());
- addFooterView(layout);
- super.setOnScrollListener(this);
-
- measureView(mRefreshView);
- mRefreshViewHeight = mRefreshView.getMeasuredHeight();
- }
然后在activity里面引用:
- ((PullToRefreshListView) getListView()).layout.setOnClickListener(new OnClickListener() {
-
- public void onClick(View v) {
- // TODO Auto-generated method stub
- ((PullToRefreshListView) getListView()).progressBar.setVisibility(View.VISIBLE);
- ((PullToRefreshListView) getListView()).textView.setText("加载中....");
- new Thread(new Runnable() {
-
- public void run() {
- // TODO Auto-generated method stub
-
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Message message=new Message();
- message.what=1;//有数据
-
- //message.what=0; 没有数据
- PushActivity.this.bottomHandler.sendMessage(message);
- }
- }).start();
-
-
- }
- });
欢迎大家批评指正。。。。。