android中接口回调问题 5
publicclassJKZX_Client{finalStringUrl="http://api.yi18.net/news/list";privateList<JKZ...
public class JKZX_Client {
final String Url = "http://api.yi18.net/news/list";
private List<JKZX_Info> JKZXDates;
public List<JKZX_Info> jsonDate(JKZXCallBack callback) {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(Url);
try {
HttpResponse resp = client.execute(get);
if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
Log.i("info",""+resp.getStatusLine().getStatusCode());
String datas = EntityUtils.toString(resp.getEntity(),"utf-8");
JSONObject json1 = new JSONObject(datas);
JSONArray array = json1.getJSONArray("yi18");
for (int i = 0, len = array.length(); i < len; i++) {
JSONObject date = array.getJSONObject(i);
JKZX_Info jkzx = new JKZX_Info();
jkzx.setAuthor(date.getString("author"));
jkzx.setTitle(date.getString("title"));
jkzx.setImgPath(date.getString("img"));
jkzx.setTime(date.getString("time"));
jkzx.setTag(date.getString("tag"));
jkzx.setId(date.getInt("id"));
jkzx.setCount(date.getInt("count"));
JKZXDates.add(jkzx);
}
if(JKZXDates==null){
callback.response(null);
}
callback.response(JKZXDates);
return JKZXDates;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public interface JKZXCallBack{
public void response(List<JKZX_Info> JKZXDates);
}
}
这是我的接口,JKZX_Info是一个实体类,请问 我怎么调用这个接口 在onCreate()中new吗?我试了下
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView) findViewById(R.id.listVIewId);
client1 = new JKZX_Client();
client1.jsonDate(new JKZXCallBack() {
@Override
public void response(List<JKZX_Info> JKZXDates) {
Toast.makeText(getApplicationContext(), "agfgsdafg", Toast.LENGTH_LONG).show();
}
});
}
运行起来根本没有反应啊 求指点。在线等 展开
final String Url = "http://api.yi18.net/news/list";
private List<JKZX_Info> JKZXDates;
public List<JKZX_Info> jsonDate(JKZXCallBack callback) {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(Url);
try {
HttpResponse resp = client.execute(get);
if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
Log.i("info",""+resp.getStatusLine().getStatusCode());
String datas = EntityUtils.toString(resp.getEntity(),"utf-8");
JSONObject json1 = new JSONObject(datas);
JSONArray array = json1.getJSONArray("yi18");
for (int i = 0, len = array.length(); i < len; i++) {
JSONObject date = array.getJSONObject(i);
JKZX_Info jkzx = new JKZX_Info();
jkzx.setAuthor(date.getString("author"));
jkzx.setTitle(date.getString("title"));
jkzx.setImgPath(date.getString("img"));
jkzx.setTime(date.getString("time"));
jkzx.setTag(date.getString("tag"));
jkzx.setId(date.getInt("id"));
jkzx.setCount(date.getInt("count"));
JKZXDates.add(jkzx);
}
if(JKZXDates==null){
callback.response(null);
}
callback.response(JKZXDates);
return JKZXDates;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public interface JKZXCallBack{
public void response(List<JKZX_Info> JKZXDates);
}
}
这是我的接口,JKZX_Info是一个实体类,请问 我怎么调用这个接口 在onCreate()中new吗?我试了下
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView) findViewById(R.id.listVIewId);
client1 = new JKZX_Client();
client1.jsonDate(new JKZXCallBack() {
@Override
public void response(List<JKZX_Info> JKZXDates) {
Toast.makeText(getApplicationContext(), "agfgsdafg", Toast.LENGTH_LONG).show();
}
});
}
运行起来根本没有反应啊 求指点。在线等 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询