-网上讲下拉刷新的例子很多,发现需要的工具类要下载啊,
找了半天也没有jar包, 只能从别人的Demo中提取出工具类了。
(libs文件夹下的两个jar包添加进去还不好使)
真是个好蠢的办法。
-**要使用 PtrClassicFrameLayout、StoreHouseHeader、
PtrClassicFrameLayout.需要导包。
或者直接将需要的文件拷入到项目中**
-
package xiaoxu.com.lifeservice.frag;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;
import in.srain.cube.views.ptr.header.StoreHouseHeader;
import xiaoxu.com.lifeservice.R;
/**
* Created by Administrator on 2016/5/2.
*/
public class TextFrag extends android.support.v4.app.Fragment {
String[] str = new String[]{"1", "2", "3", "4", "5", "6", "7","8","9","10"};
ListView listView;
PtrClassicFrameLayout mPtrFrame;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_demo_ptr, null);
mPtrFrame = (PtrClassicFrameLayout) view.findViewById(R.id.rotate_head_list_view);
listView = (ListView) view.findViewById(R.id.list_view);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
List<String> data = new ArrayList();
data.addAll(Arrays.asList(str));
ArrayAdapter adapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1,data);
listView.setAdapter(adapter);
StoreHouseHeader header = new StoreHouseHeader(getActivity());
header.setPadding(0,20,0,0);
header.initWithString("Fine");
header.setTextColor(Color.GRAY);
mPtrFrame.setHeaderView(header);
mPtrFrame.addPtrUIHandler(header);
mPtrFrame.setLastUpdateTimeRelateObject(this);
mPtrFrame.setPtrHandler(new PtrHandler() {
@Override
public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
//返回是否满足下拉刷新的条件,这里返回的是PtrDefaultHandler对一些行为进行的默认判断,
return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
}
@Override
public void onRefreshBegin(PtrFrameLayout frame) {
//在这里执行刷新的逻辑。刷新完成后调用//mPtrFrame.refreshComplete();通知完成刷新,刷新显示的view将消失。这里是文字Fine。
Log.v("TextFrag", " 下拉刷新");
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<in.srain.cube.views.ptr.PtrClassicFrameLayout
android:id="@+id/rotate_head_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
cube_ptr:ptr_duration_to_close="300"
cube_ptr:ptr_duration_to_close_header="2000"
cube_ptr:ptr_keep_header_when_refresh="true"
cube_ptr:ptr_pull_to_fresh="false"
cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"
cube_ptr:ptr_resistance="1.7">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</in.srain.cube.views.ptr.PtrClassicFrameLayout>
</LinearLayout>