Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将字符串传递给AsyncTask doInBackground,并返回ArrayList<;字符串>;执行_Android_Android Asynctask - Fatal编程技术网

Android 如何将字符串传递给AsyncTask doInBackground,并返回ArrayList<;字符串>;执行

Android 如何将字符串传递给AsyncTask doInBackground,并返回ArrayList<;字符串>;执行,android,android-asynctask,Android,Android Asynctask,如何将字符串传递给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&l

如何将字符串传递给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>         

    }
}
公共类计算任务{
进程对话;
@凌驾
受保护的void onPreExecute(){
}
受保护的ArrayList doInBackground(ArrayList…传递){
//在这里,我想从URL字符串pars数据到ArrayList
返回数组列表;
}
受保护的void onPostExecute(ArrayList结果){
//如何处理ArrayList
}
}
公共类计算任务{
进程对话;
@凌驾
受保护的void onPreExecute(){
}
受保护的ArrayList doInBackground(字符串…传递){
字符串URLStr=传递[0];//因为您只传递1个url,所以这对u有效
ArrayList ArrayList=新的ArrayList();
//在这里,你做你想做的事情,将字符串数据添加到ArrayList并返回
返回数组列表;
}
受保护的void onPostExecute(ArrayList结果){
//如何处理ArrayList
}
}

是否有什么东西不起作用?你的问题是什么?为什么当我这样做的时候,我在onPostExecute中有空数组?你能分享你正在做的代码吗。如果您没有在arraylist中添加任何字符串数据,那么只有u可能会使其为空
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>         

    }
}