1,属性详解
- <com.handmark.pulltorefresh.library.PullToRefreshListView
- xmlns:ptr="http://schemas.android.com/apk/res-auto"
- android:id="@+id/pull_refresh_list"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:cacheColorHint="#00000000"
- android:divider="#19000000"
- android:dividerHeight="4dp"
- android:fadingEdge="none"
- android:fastScrollEnabled="false"
- android:footerDividersEnabled="false"
- android:headerDividersEnabled="false"
- android:smoothScrollbar="true"
- ptr:ptrMode="both" >
- </com.handmark.pulltorefresh.library.PullToRefreshListView>
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);
}