java 在 doinbackground 中获取传递给 asynctask 的数组列表值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14413698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get arraylist values passed to asynctask at doinbackground
提问by user1910290
I have an Asynctask setup I pass an Arraystring like this
我有一个 Asynctask 设置,我传递了一个这样的 Arraystring
ArrayList<String> creds = new ArrayList<String>();
creds.add(string1);
creds.add(string2);
new myasynctask().execute(credentials);
asynctask methodclass myasynctask extends AsyncTask, Integer , String>
asynctask 方法类 myasynctask 扩展了 AsyncTask, Integer , String>
DOinbackground
背景资料
protected String doInBackground(ArrayList<String>... creds)
{ String lol1= creds[0].toString();
String lol2= creds[1].toString();
........rest of the code
}
I get an Array index out of bond exception how do I pass tow values into the doinbackground method and get both of them at once.
我从债券异常中获得了一个数组索引,我如何将两个值传递到 doinbackground 方法中并同时获得它们。
回答by Sanket Kachhela
you can get value by this code
您可以通过此代码获得价值
class test extends AsyncTask<ArrayList<String>, Void, Void>
{
@Override
protected Void doInBackground(ArrayList<String>... creds) {
// TODO Auto-generated method stub
String str1 = creds[0].get(0);
String str2 = creds[0].get(1);
return null;
}
}
回答by Aerrow
To get the arraylist value,
要获取数组列表值,
ArrayList<String> recList= new ArrayList<String>();
ArrayList<String> arrayListVal= creds[0];
回答by ρяσ?ρ?я K
get arraylist as in doInBackground
method of AsyncTask :
在 doInBackground
AsyncTask 的方法中获取数组列表:
private class myAsyncTask extends AsyncTask<ArrayList<String>, Void, String> {
@Override
protected String doInBackground(ArrayList<String>... params) {
ArrayList<String> lol1= params[0]; //<< here retrieve Array from varargs
return null;
}
// your code here
回答by Janmejoy
Try the following link
试试下面的链接
Passing arguments to AsyncTask, and returning results
protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> passed = passing[0]; //get passed arraylist
//Some calculations...
return result; //return result