首先說 PulltorefreshListView PullToRefreshGridView PullToRefreshWebView PullToRefreshScrollView PullToRefreshExpandableListView PullToRefreshHorizontalScrollView PullToRefreshBase PullToRefreshAdapterViewBase 一共有這么多樣式
pulltoRefreshView 添加n個headView那么它被點擊的項的position值就會比真實的多n+1(真實測試值)
這里真實的值是指適配器中數據的索引(0,1,2,3,4,。。。。)
在fragment中添加點擊事件時listView.setAdapter一定是在最后更新否則前邊更新的都會無效
此處的例子是pulltorefreshlistview 切換適配器時的例子(點擊不同的區域更新適配器)
@Override public void onClick(View v) { switch (v.getId()) { case R.id.linear_zuire_huodongfragment: tv_zuire.setTextColor(Color.BLUE); line_zuire.setBackgroundColor(Color.BLUE); tv_zuixin.setTextColor(Color.BLACK); line_zuixin.setBackgroundColor(Color.parseColor("#42050206")); listView.setAdapter(hotAdapter);//-------------------------此處更新適配器一定要在最后更新否則前邊的ui操作無效 break; case R.id.linear_zuixin_huodongfragment: tv_zuire.setTextColor(Color.BLACK); line_zuire.setBackgroundColor(Color.parseColor("#42050206")); tv_zuixin.setTextColor(Color.BLUE); line_zuixin.setBackgroundColor(Color.BLUE); listView.setAdapter(newAdapter);//-------------------------此處更新適配器一定要在最后更新否則前邊的ui操作無效 break; } }
設置上啦加載 下拉刷新的布局
private void setPullDownLayout() { SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); //獲取下啦布局 ILoadingLayout proxy=listView.getLoadingLayoutProxy(true,false);//true,false 意思是下拉時的布局 proxy.setPullLabel("下拉刷新"); proxy.setReleaseLabel("放開以刷新。。。"); proxy.setRefreshingLabel("玩命刷新。。。"); proxy.setLastUpdatedLabel("最后刷新時間:"+format.format(new Date())); //設置上啦加載的布局 /*ILoadingLayout proxy2=listView.getLoadingLayoutProxy(false,true); //false true 意思是上拉時的布局 proxy2.setPullLabel("請上拉加載"); proxy2.setReleaseLabel("放開以加載。。。"); proxy2.setRefreshingLabel("玩命加載。。。"); proxy2.setLastUpdatedLabel("最后加載時間:"+format.format(new Date()));*/ }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- ptr:ptrAnimationStyle="flip" flip:翻轉 rotate:旋轉--> <!-- ptr:ptrShowIndicator="true" 右上角 右下角出現箭頭--> <com.handmark.pulltorefresh.library.PullToRefreshListView xmlns:ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/pullToRefresh" android:layout_width="match_parent" android:layout_height="wrap_content" ptr:ptrDrawable="@drawable/default_ptr_flip" ptr:ptrAnimationStyle="flip" //這個樣式反轉后會變為圓形 ptr:ptrHeaderBackground="#383838" ptr:ptrHeaderTextColor="#FFFFFF" /> </LinearLayout>