2

I am storing the string values in arraylist in Select.java page. Now I need to get those string values into other page i.e review.java page. How to do that? Please help me regarding this?

Thanks in Advance

RaagaSudha
  • 397
  • 5
  • 17
  • 38

3 Answers3

2

Either make this arraylist as public static or use Intent.putStringArrayListExtra(); and pass it to your review.java (If both java class are activity).

something like,

In Select.java

        Intent intent = new Intent(Select.this, review.class);
        intent.putStringArrayListExtra("stock_list", stock_list);
        startActivity(intent);

and In review.java

Intent i = getIntent();  
stock_list = i.getStringArrayListExtra("stock_list");

Here stock_list is a String ArrayList...

You can also use Intent.putExtra("keyName", "somevalue"); for passing ArrayList..

user370305
  • 108,599
  • 23
  • 164
  • 151
  • hi thank you..I have used public static and sent the values... – RaagaSudha Dec 03 '11 at 04:47
  • @user370305:Hello,maybe you could help me here?? http://stackoverflow.com/questions/8703103/android-make-calculations-with-input-data-show-graphs – George Jan 03 '12 at 11:39
2

You can use Extras to pass data to an activity when you start it. An example is:

Intent intent = new Intent(context, review.class);
intent.putExtra("YOUR_DATA_KEY", arrayListVar);
startActivity(intent);

check out the "Extras" section of the docs for more info. This is the preferred method of sharing information across activities (you shouldn't use public variables since that would introduce a dependency between your two activities when all they really need to depend on is data).

Chris
  • 22,923
  • 4
  • 56
  • 50
0

Declare this in your Select.java

static String[] x=new String[]{"a","b","c"}; globally. Making them static can get you access in other class.

in review.java create object static Select dd and static Select[] all;

dd = new Select("a","n","m"); all[i]=dd;

Rashmi.B
  • 1,787
  • 2
  • 18
  • 34