前台代码:
<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]);
}
}