当我尝试在arrivalInfoArrayList.size()
的{{1}}中打印onPostExecute
时,结果就是我想要的。
尽管在Tab1Fragment class
之外,它始终打印onPostExecute
有什么问题...
请帮助我...
ArrivalAsync.java
0
TabFragment1.java
public class ArrivalAsync extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
try {
return downloadByUrl(urls[0]);
} catch (Exception e) {
return "Download failed";
}
}
public String downloadByUrl(String apiUrl) throws IOException {
HttpURLConnection conn = null;
BufferedReader bufferedReader;
String data;
try {
URL url = new URL(apiUrl);
conn = (HttpURLConnection)url.openConnection();
BufferedInputStream bufferedInputStream = new BufferedInputStream(conn.getInputStream());
bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream, "utf-8"));
String line = null;
data = "";
while((line = bufferedReader.readLine()) != null) {
data += line;
}
return data;
} finally {
conn.disconnect();
}
}
}
答案 0 :(得分:-1)
使用
new calc_stanica().execute(arraylistobjext);
访问AsyncTask
public class calc_stanica extends AsyncTask<String, Void, ArrayList<String>> {
@Override
protected ArrayList<String> doInBackground(String... args) {
...
}
@Override
protected void onPostExecute(ArrayList<String> result) {
... //do something with the result list here
}
}