• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to add String[] into List of Setter and Getter

Varun7952

Lurker
Aug 7, 2016
1
0
Hi i am working in AsyncTask <String, Void, List<WrapperClass>> and my WrapperClass is

public class WrapperClass {
List<String[]> list=null;


public List<String[]> getList() {
return list;
}

public void setList(List<String[]> list) {
this.list = list;
}



And in AsyncTask's method -
public List<WrapperClass > doInBackground(Void... params) {
List<WrapperClass > users = new AraryList<WrapperClass >();
String[] Name;
String[] ImagePath;
// TODO: HTTP Request
// TODO: Parse JSON string - store into list
Name=childObject.getString("Name")
ImagePath=childObject.getString("Image")

}

Now i want to add Name[] and ImagePath[] into List<WrapperClass> and then return users as result of doinbackground but i am doing something wrong cuz both String[] not adding into List

Please help me


 
Last edited:
Difficult to understand what exactly is your problem, as the above code doesn't call setList() on your Wrapper class.
In fact it doesn't appear to do anything much, as you've commented out most of the code.

You refer to "user", but don't explain what this is, and how it's used, there's no reference to this variable in your code.

Plus there are typos in the code, so it wouldn't even compile. In particular, this line is not correct

Code:
List<WrapperClass > users = new AraryList<WrapperClass >();

Also, put your code in [code][/code] tags, as requested in the PLEASE READ ME BEFORE ASKING A QUESTION sticky post at the top of this forum.

Can you please clean up your code, say exactly what you're trying to do, and state clearly what is the problem.

Thanks.
 
Upvote 0
Ok not sure what edits you made to the above, but if you want to construct a List of anything, then you'll need a loop of some description.
You also need to create new instances of the object to put in the list. So something like this

Code:
boolean finished = false;
while (!finished) {
  WrapperClass user = new WrapperClass();
  // TODO: HTTP Request
  // Set data in the WrapperClass
  users.add(user);
  // set finished = true if we're done
}
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones