Volley请求
来源:互联网 发布:超次元矩阵狂三 编辑:程序博客网 时间:2024/05/21 18:44
public classMainActivityextendsAppCompatActivity {
intstartNum=0;
privateXListViewxlv;
privateJSONArrayjsonArray;
privateMyAdapteradapter;
privateCheckBoxcheckBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xlv= (XListView) findViewById(R.id.xlv);
checkBox= (CheckBox) findViewById(R.id.check);
setxlvdata();
getDate();
}
private void setxlvdata() {
xlv.setPullRefreshEnable(true);
xlv.setPullLoadEnable(true);
xlv.setXListViewListener(newXListView.IXListViewListener() {
@Override
public void onRefresh() {
checkBox.setChecked(false);
startNum=0;
getDate();
xlv.postDelayed(newRunnable() {
@Override
public void run() {
xlv.stopRefresh();
}
},2000);
}
@Override
public void onLoadMore() {
xlv.postDelayed(newRunnable() {
@Override
public void run() {
checkBox.setChecked(false);
startNum++;
getDate();
xlv.stopLoadMore();
}
},2000);
}
});
getDate();
}
private void getDate() {
String url ="http://www.93.gov.cn/93app/data.do?"+"channelId="+0+"&startNum="+startNum;
//设置请求队列
Log.d("sssssssssssssssssssss",url);
RequestQueue queue= Volley.newRequestQueue(this);
StringRequest request=newStringRequest(url,newResponse.Listener<String>() {
@Override
public void onResponse(String s) {
try{
JSONObject jsonobject=newJSONObject(s);
JSONArray data=jsonobject.getJSONArray("data");
if(startNum==0){
jsonArray=newJSONArray();
}
//把数据添加到jsonArray中去
for(inti =0; i < data.length(); i++) {
jsonArray.put(data.get(i));
}
initListView(jsonArray);
}catch(JSONException e) {
e.printStackTrace();
}
}
},newResponse.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
//把请求方式添加到队列
queue.add(request);
}
private void initListView(JSONArray jsonArray) {
if(adapter==null){
adapter=newMyAdapter(this, jsonArray, newMyAdapter.OnCheckLitener() {
@Override
public void onCheck(Boolean check) {
checkBox.setChecked(check);
}
});
adapter.setData(jsonArray);
xlv.setAdapter(adapter);
}else{
adapter.setData(jsonArray);
}
}
public void oncheck(View view){
switch(view.getId()){
caseR.id.check:
booleanfalg=((CheckBox)view).isChecked();
if(falg){
adapter.niticheck(falg);
}else{
adapter.niticheck(falg);
}
break;
}
}
}
0 0
- Volley请求
- Volley请求
- Volley请求
- Volley请求
- volley请求搭配图片请求
- volley请求数据(二)
- 网络请求框架---Volley
- android Volley JSON请求
- Volley网络请求框架
- Volley的Https请求
- volley JSON请求数据
- volley请求原理
- 网络请求框架---Volley
- 网络请求框架-Volley
- Volley发送StringRequest请求
- volley使用 POST请求
- Volley多次请求 RetryPolicy
- volley JSON请求数据
- Java 实例
- 使用ibping命令来测试RDMA 连接性
- 在spring中使用数据校验
- 二叉树的镜像
- iBET Online Casino Labour Day Free RM10 to New Member(iBET, iBET Free Credit Promotion, iBET Labour
- Volley请求
- Android 自动填充短信验证码
- JavaScript之对象、构造函数、包装类
- sql server t-sql脚本转成oracle plsql
- 遍历嵌套Map
- clips系列二-clips调用外部函数
- HDU 6019 set
- 扫描二维码和生成二维码
- yum 命令