pulltorefresh使用详解

来源:互联网 发布:仿砍柴网源码破解版 编辑:程序博客网 时间:2024/05/22 16:45

1,属性详解



  1.     <com.handmark.pulltorefresh.library.PullToRefreshListView  
  2.         xmlns:ptr="http://schemas.android.com/apk/res-auto"  
  3.         android:id="@+id/pull_refresh_list"  
  4.         android:layout_width="fill_parent"  
  5.         android:layout_height="fill_parent"  
  6.         android:cacheColorHint="#00000000"  
  7.         android:divider="#19000000"  
  8.         android:dividerHeight="4dp"  
  9.         android:fadingEdge="none"  
  10.         android:fastScrollEnabled="false"  
  11.         android:footerDividersEnabled="false"  
  12.         android:headerDividersEnabled="false"  
  13.         android:smoothScrollbar="true"  
  14.         ptr:ptrMode="both" >  
  15.     </com.handmark.pulltorefresh.library.PullToRefreshListView>  
  16.   
2.代码使用详解

product_content_list.setMode(Mode.BOTH);
product_content_list.setOnRefreshListener(new OnRefreshListener2<ListView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
//显示时间
String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
product_condition_text = product_condition.getText().toString();
loadProductList(product_condition_text, 1);
current=1;
}

@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
current=current+1;
product_condition_text = product_condition.getText().toString();
loadProductList(product_condition_text, current);
}

});

3.handler中的代码

public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 1:
list=(List<ProductData>) msg.obj;
if(current==1){
adapter = new MyAdapter(list);
refreshableView.setAdapter(adapter);
}else {
adapter.notifyDataSetChanged();
}
product_content_list.onRefreshComplete();
dialogUtils.dissDialog();
break;
case 2:
adapter.notifyDataSetChanged();
dialogUtils.dissDialog();
break;
default:
break;
}
};

4.loadHtttp

TwitterRestClient.get2(Constant.PRODUCT_LIST+id, params, new AsyncHttpResponseHandler() {



@Override
public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
String string=new String(arg2);
Logger.i(TAG,"商品详情"+string);
ProductListBean productListBean = gs.fromJson(string, ProductListBean.class);
if(productListBean==null){
dialogUtils.dissDialog();
product_content_list.onRefreshComplete();
return;
}
if(pageNumber==1){
list.clear();
list = productListBean.data;
}else {
list.addAll((productListBean.data));
}

if(list.size()<0){
showToast("暂无数据");
return;
}
Message message = handler.obtainMessage();
message.obj=list;
message.what=1;
handler.sendMessage(message);
}


0 0
原创粉丝点击