您好,我正在尝试编写一段代码,尝试使用downloadtask下载多个urls,并将它们转换为json对象,然后将它们添加到列表中,但我只获得一个对象多次,而不是每次都不同,我的代码是:
int x = 1;
while(x<=6) {
try {
result = tasknew.execute("url"parts[x]+ "rest of the url").get();
} catch (Exception e) {
e.printStackTrace();
}
try {
JSONObject jsonObject = new JSONObject(result);
String title = jsonObject.getString("title");
Log.i("title", title);
listobject.add(title);
} catch (Exception e) {
e.printStackTrace();
}
x=x+1;
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, headlines);
list.setAdapter(arrayAdapter);发布于 2020-06-23 15:13:39
嘿,伙计们,我想出了答案,因为一个异步任务只能运行一次,这就是为什么我的下载任务只有执行once.so才能多次运行它,只要替换新闻=新的Downloadtask..that就可以工作了
https://stackoverflow.com/questions/62513440
复制相似问题