PullToRefreshGridView
来源:互联网 发布:淘宝店铺话费充值软件 编辑:程序博客网 时间:2024/05/23 22:17
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.GridView;
import com.example.bean.Myinfo;
import com.example.bean.Myinfo.MyData;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshGridView;
public class SendActivity extends Activity {
private PullToRefreshGridView gv_2;
private String url;
private int index = 10;
private Adapter adapter;
private List<MyData> data = new ArrayList<Myinfo.MyData>();
private List<MyData> list=new ArrayList<Myinfo.MyData>();
String id;
private int port=1;
Handler handler=new Handler(){
public void handleMessage(Message msg) {
data=(List<MyData>) msg.obj;
if (port==1) {//也就是说第一次联网请求数据
list.clear();//清空集合中的数据
}
list.addAll(data);//将这个数据添加到适配器器上面展示一下
if (adapter==null) {
adapter=new Adapter(list, SendActivity.this);
gv_2.setAdapter(adapter);
gv_2.onRefreshComplete();
}else {
//适配器通知数据发生改变
adapter.notifyDataSetChanged();
gv_2.onRefreshComplete();
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send);
gv_2 = (PullToRefreshGridView) findViewById(R.id.gv_2);
Intent intent = getIntent();
id = intent.getStringExtra("id");
gv_2.setMode(Mode.BOTH);
gv_2.setOnRefreshListener(new OnRefreshListener2<GridView>() {
@Override
public void onPullDownToRefresh(
PullToRefreshBase<GridView> refreshView) {
MyAsyncTask asyncTask = new MyAsyncTask();
index = index + 10;
asyncTask.execute();
}
@Override
public void onPullUpToRefresh(
PullToRefreshBase<GridView> refreshView) {
MyAsyncTask asyncTask = new MyAsyncTask();
index = index + 10;
asyncTask.execute();
}
});
}
class MyAsyncTask extends AsyncTask<Void, Void, List<MyData>> {
@Override
protected List<MyData> doInBackground(Void... params) {
List<MyData> list = null;
url = "http://apis.juhe.cn/goodbook/query?key=9d6ef8c31647a206e05fcaff70527182&catalog_id="
+ id + "&rn=10&pn=20";
port++;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == 200) {
HttpEntity entity = httpResponse.getEntity();
String string = EntityUtils.toString(entity, "UTF-8");
Gson gson = new Gson();
Myinfo json = gson.fromJson(string, Myinfo.class);
list=json.getResult().getData();
Log.i("TAG", list.size()+"");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
@Override
protected void onPostExecute(List<MyData> result) {
Message message=Message.obtain();
message.obj=result;
handler.sendMessage(message);
super.onPostExecute(result);
}
}
}
0 0
- PullToRefreshGridView
- PullToRefreshGridView
- PullToRefreshGridView
- PullToRefreshGridView
- PullToRefreshGridView下拉刷新
- PullToRefreshGridView添加头部
- PullToRefreshGridView的使用
- pullToRefreshGridView里面不显示数据
- 上拉分页加载PullToRefreshGridView
- PullToRefreshGridView中xml的配置
- PullToRefreshGridView上拉刷新,下拉加载
- 开源插件 PullToRefresh: PullToRefreshListView / PullToRefreshGridView 实例详解
- PullToRefreshGridView添加头部, GridView添加头部head的PullToRefresh
- PullToRefreshGridView 带下拉刷新,上拉加载的GridView控件
- PullrefreshLibrary(PullToRefreshGridView)上拉刷新,下拉加载+异步AsyncTask(二)
- 抽屉布局+Fragment+TabLayout上导航栏+PullToRefreshListView+轮播图+PullToRefreshGridView
- 开源项目PullToRefresh详解(二)——PullToRefreshGridView
- PullToRefreshGridView改变下拉的文字(2015.8.19第一次使用csdn博客)
- [算法]负载均衡
- 快速理解RxJava源码的设计理念
- 400 (bad request) post
- 如何不用写一行代码就能学习软件开发
- Android 百个项目的源代码
- PullToRefreshGridView
- 广播(BroadcastReceiver)
- dd命令详解及实例
- Nginx配置文件nginx.conf中文详解
- RTMP直播应用与延时分析
- linux系统启动过程
- 非标准base64编码
- mybatis学习(一) 快速入门
- hibernate 执行原生sql,select返回string,long