还要在Application下写一句话:
android:networkSecurityConfig="@xml/network_security_config"
这是关于网络安全的,必须写!!!所以还需要写network_security_config.xml
RecyclerTask.java
package com.example.myapplication.Task;
import android.os.AsyncTask;
import com.example.myapplication.Bean.NetworkJson;
import com.google.gson.Gson;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class RecyclerTask extends AsyncTask {
//获得要解析的json字符串
private String mEnd;
private String city;
private List mJson;
//查询接口的api
private String climate_tep = "http://www.qubaobei.com/ios/cf/dish_list.php?stage_id=1&limit=20&page=1";
@Override
protected String doInBackground(Void...voids) {
//地址字符串
try {
URL url = new URL(climate_tep);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//请求方法
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(10000);
conn.setRequestProperty("Accept", "*
private int ret;
private List data;
public int getRet() {
return ret;
}
public void setRet(int ret) {
this.ret = ret;
}
public List getData() {
return data;
}
public void setData(List data) {
this.data = data;
}
public static class DataBean {
private String id;
private String title;
private String pic;
private String collect_num;
private String food_str;
private int num;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public String getCollect_num() {
return collect_num;
}
public void setCollect_num(String collect_num) {
this.collect_num = collect_num;
}
public String getFood_str() {
return food_str;
}
public void setFood_str(String food_str) {
this.food_str = food_str;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
}
}
network_security_config.xml
总结
也没有多少代码吧,如果有不懂的可以自己调试或者问我也行!
另外,我没有给列表项添加点击事件!
再上一个GIF图吧,哈哈哈!!!
作者:^ 不渡^