Reputation: 397
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...
Upvotes: 0
Views: 2005
Reputation: 29642
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;
}
Upvotes: 1
Reputation: 67286
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.
Upvotes: 0
Reputation: 441
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();
Upvotes: 0