How to add an ArrayList to other ArrayLists in Android?

I created three ArrayLists and stored data. I need to pass an arraydata to other pages, so I add my individual array to the main array. However, when I add an array to other arrays, the data is not added to the array. This is my code:

static ArrayList<ArrayList<String>> stringList1=new ArrayList<ArrayList<String>>();
static ArrayList<ArrayList<String>> stringList3; 

stringList1 = Mypage.stringList1;

 ArrayList<String> optionlist = new ArrayList<String>();
stringList3 = new ArrayList<ArrayList<String>>();stringList3 = dbAdapter.selectRecordsFromDBList(query2, null); 
 for (int i = 0; i < stringList3.size(); i++) {
    optionlist = stringList3.get(i);
    System.out.print("option list size");
    System.out.print(optionlist.size());
    stringList1.add(optionlist);
    System.out.println("total stringlist1"+stringList1.get(0));

I get the array value of stringlist1 from mypage and access it in the new page. In the new page, I tried to add the optionlist array to stringlist1 by giving stringlist1. Add (optionlist), but the data was not added. What went wrong? Please help me solve this problem... Thank you first

resolvent:

After seeing your code, I guess you have a problem. The elements of ArrayList are not copied to another ArrayList. If this is your problem, change your code as follows

static ArrayList<ArrayList<String>> stringList1=new ArrayList<ArrayList<String>>();
static ArrayList<ArrayList<String>> stringList3; 

stringList1 = Mypage.stringList1;

ArrayList<String> optionlist;
stringList3 = new ArrayList<ArrayList<String>>();
stringList3 = dbAdapter.selectRecordsFromDBList(query2, null); 

 for (int i = 0; i < stringList3.size(); i++) {
    optionlist = new ArrayList<String>();
    optionlist = stringList3.get(i);
    System.out.print("option list size");
    System.out.print(optionlist.size());
    stringList1.add(optionlist);
    System.out.println("total stringlist1"+stringList1.get(0));
 }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>