2017-04-13 59 views
-1

如何將String傳遞給doInBackground並將ArrayList返回給onPostExecute。 我想要傳遞html URL到Asyntask doInBackground和onPostExecute我想用UI做事情。如何將字符串傳遞給AsyncTask doInBackground,並返回ArrayList <String> onPostExecute

我想嘗試這樣

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>   

    } 
} 
+0

爲什麼當我這樣做時,我在onPostExecute中有空數組? – smiljka

+0

你能分享你的代碼嗎?如果你沒有在數組列表中添加任何字符串數據,所以只有你可能已經清空了 –

相關問題