如何将String传递给doInBackground并将ArrayList返回到onPostExecute。 我想要将html URL传递给Asyntask doInBackground和onPostExecute我想用UI做事。
我想尝试这样的事情
new calc_stanica().execute("where we send URL as String");//
和AsynTask:
public class calc_stanica extends AsyncTask<String, Void, ArrayList<String>> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
}
protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
// here i want to from URL String pars data to ArrayList<String>
return ArrayList<String>;
}
protected void onPostExecute(ArrayList<String> result) {
// do with ArrayList<String>
}
}
答案 0 :(得分:0)
public class calc_stanica extends AsyncTask<String, Void, ArrayList<String>> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
}
protected ArrayList<String> doInBackground(String... passing) {
String URLStr=passing[0];//as you are passing 1 url only so this will work for u
ArrayList<String> arraylist=new ArrayList<String>();
// here u do the things u wana do and add the String data to ArrayList<String> and return
return arraylist;
}
protected void onPostExecute(ArrayList<String> result) {
// do with ArrayList<String>
}
}