PullToRefresh 针对SrcollView 下拉刷新

前台代码:
    <com.handmark.pulltorefresh.library.PullToRefreshScrollView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/ptrScrollView_home"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ptr:ptrAnimationStyle="rotate"
        ptr:ptrMode="both" >
        <LinearLayout
            android:id="@+id/LinearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <include
                android:id="@+id/item_home_spec"
                layout="@layout/item_home_spec" />
        </LinearLayout>
    </com.handmark.pulltorefresh.library.PullToRefreshScrollView>
后台代码:
package com.example.epcrm.fragment;

import java.util.LinkedList;
import java.util.List;

import com.example.epcrm.R;
import com.example.epcrm.activity.SplashActivity;
import com.example.epcrm.models.tb_product;
import com.example.epcrm.util.Utils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import android.R.integer;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.handmark.pulltorefresh.library.*;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;

public class Fragment_Home extends Fragment {
	private View view;
	@ViewInject(R.id.txtview1)
	private TextView mtxtView;
	@ViewInject(R.id.ptrScrollView_home)
	private PullToRefreshScrollView mPtrScrollView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		view = inflater.inflate(R.layout.fragment_home, container, false);
		ViewUtils.inject(this, view);
		initView();
		return view;
	}

	void initView() {
		mPtrScrollView.setOnRefreshListener(new OnRefreshListener<ScrollView>() {
					public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
						//String label = Utils.getCurrentTime(); 
				        // Update the LastUpdatedLabel  
				        //refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);  				        
						new GetDataTask().execute();
					}
				});
	}

	@OnClick(R.id.imageView1)
	public void testButtonClick(View v) { // 方法签名必须和接口中的要求一致
		Intent intent = new Intent(getActivity(), SplashActivity.class);
		startActivity(intent);
	}

	private class GetDataTask extends AsyncTask<Void, Void, String[]> {
		protected String[] doInBackground(Void... params) {
			String[] _array={"郑州"};
			// 下拉刷新
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
			}
			return _array;
		}

		protected void onPostExecute(String[] result) {
			// 更新数据操作
			updateView(result);
			mPtrScrollView.onRefreshComplete();// 关闭刷新动画
		}
	}
	//更新页面数据
	void updateView(String[] result) {
		
		mtxtView.setText(result[0]);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值