1. Download our Official Android App: Forums for Android!

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

Discussion in 'Android Development' started by Varun7952, Aug 7, 2016.

  1. Varun7952

    Varun7952 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Aug 7, 2016

    Aug 7, 2016
    1
    0
    5
    Male
    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




     

    Advertisement

    #1 Varun7952, Aug 7, 2016
    Last edited: Aug 7, 2016
  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,866
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,866
    11,495
    1,988
    Male
    Software developer
    South West of England
    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 (Text):
    1.  
    2. List<WrapperClass > users = new AraryList<WrapperClass >();
    3.  
    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.
     
  3. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,866
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,866
    11,495
    1,988
    Male
    Software developer
    South West of England
    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 (Text):
    1.  
    2. boolean finished = false;
    3. while (!finished) {
    4.   WrapperClass user = new WrapperClass();
    5.   // TODO: HTTP Request
    6.   // Set data in the WrapperClass
    7.   users.add(user);
    8.   // set finished = true if we're done
    9. }
    10.  
     

Share This Page

Loading...