0

I am storing my data into arraylist of one class and sending that arraylist data to other class. But the values of the arraylist are not coming to the other class. I have given like

page1.java

static ArrayList<ArrayList<String>> stringList1; 

page2.java

static List<ArrayList<String>> mystringList1 = new ArrayList<ArrayList<String>>();
 mystringList1 = page1.stringList1;

Dont know where I am going wrong..but tried a lot to send the data....Please help me regarding this...

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
RaagaSudha
  • 397
  • 5
  • 17
  • 38

3 Answers3

1

you can try getter setter method for transferring values between two classes. I think that would be best for your project.

For e.g.

private String myValue; 

public void setValue ( String myValue )
{
     this.myValue = myValue;
}

public String getValue()
{
      return myValue;
}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
0

Make it public static and you will be able to pass your ArrayList to Another Class. But, better way would be to use Serializable or Parcelable to pass it.

UPDATE

Application Class From the Docs.

Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's tag, which will cause that class to be instantiated for you when the process for your application/package is created

Other Option is you can create a class that extends Application and you can use a getter setter for the ArrayList there in the Application class. Application Class is available to your whole Application and you can get the values everywhere using the Application Context.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
  • Hi thanks for the response...can you give an example for that please...? – RaagaSudha Jan 02 '12 at 05:41
  • 1
    @Sweety: using Application class is also not a good solution, you should use `Parcelable ArrayList` you can see [here](http://stackoverflow.com/a/7400675/593709) and [here](http://stackoverflow.com/a/8687006/593709) – Adil Soomro Jan 02 '12 at 05:46
  • @Sweety Adil has given you the Examples link fpr Serializable & Parcelable and for Application class here is the [link](http://www.xoriant.com/blog/mobile-application-development/android-application-class.html). – Lalit Poptani Jan 02 '12 at 05:53
  • hi thanks for your valuable suggestions...I had made a small mistake...i.e I am clearing the array in the other page..thats why I am unable to get the array data to page2 class..now it is workig fine – RaagaSudha Jan 02 '12 at 09:08
0

This would help u i think.

**page1.java**

    static ArrayList<ArrayList<String>> stringList1; 

    public static ArrayList<ArrayList<String>> getstringList1()
    {
        return stringList1;
    }

**page2.java**

    ArrayList<ArrayList<String>> mystringList1  = page1.getstringList1();
stella
  • 441
  • 4
  • 12