PullToRefresh上拉加载,下拉刷新
首先导入PullToRefresh的Module
布局代码:
<com.handmark.pulltorefresh.library.PullToRefreshListView
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"
>
</com.handmark.pulltorefresh.library.PullToRefreshListView>
public class MainActivity extends BaseActivity {
PullToRefresh
public static final String TAG="MainActivity";
int page=1;
List<Ganh.DataBean> mList=new ArrayList();
ExpoAdapter mExAd;
private Message message1;
private TextView viewById;
PullToRefreshListView pull_refresh_list;
Ganh ganh;
private List<Ganh.DataBean> data;
Handler mHandler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case 0:
String t= msg.obj.toString();
Gson gson=new Gson();
ganh = gson.fromJson(t,Ganh.class);
data = ganh.getData();
mList.addAll(data);
if(mExAd==null){
mExAd = new ExpoAdapter(MainActivity.this,mList);
pull_refresh_list.setAdapter(mExAd);
mExAd.notifyDataSetChanged();
}else {
mExAd.notifyDataSetChanged();
}
pull_refresh_list.onRefreshComplete();
break;
}
}
};