1

I am doing an android project using php,mysql using xamp server. I have retrieved the values into a ListView from server database using json parser and displayed them successfully in activity1.

Now i need codings for, "when i press a button it should navigate into a new page named activity2 and the ListView values in activity1 should display in new ListView on activity2.

Thank you in advance.

Rami
  • 7,879
  • 12
  • 36
  • 66
Aboo Sidhu
  • 35
  • 12
  • 1
    Look in this link [passing-arraylist-through-intent][1] [1]: http://stackoverflow.com/questions/5374546/passing-arraylist-through-intent – Prashant Jajal Dec 04 '14 at 05:14
  • either do that what is told above...or just make that arraylist static ...then you can access it from other class.. – Harry Sharma Dec 04 '14 at 05:16

2 Answers2

0

in your starting intent you need to add data in intent :

 Intent intent = new Intent(this, abc.class);
  intent.putExtra("data", data);
   startActivity(intent);

In your receiving intent you need to do:

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

The way you have it you've just created a new empty intent without any extras.

If you only have a single extra you can condense this down to:

stock_list = getIntent().getStringArrayListExtra("data");

A-Droid Tech
  • 2,301
  • 24
  • 33
  • 1
    super.onCreate(savedInstanceState); setContentView(R.layout.activity_token); ArrayList list = new ArrayList(); Intent i = getIntent(); list= i.getStringArrayListExtra("list"); ListView listView = (ListView) findViewById(R.id.listView1); final ArrayAdapter adapter = new ArrayAdapter(token.this, android.R.layout.simple_list_item_1, list); listView.setAdapter(adapter); is there any mistakes in this code because its autoamtically closing when this activity is open – Aboo Sidhu Dec 04 '14 at 05:46
  • check out the the debug that will track you that where is problem – A-Droid Tech Dec 04 '14 at 05:57
  • Excuse me What is stock_list here..where does it came from??and what will be its future function? – Aboo Sidhu Dec 04 '14 at 14:09
0

Make a static function which contains the data for the list view and call the same function in the both activities. Hope it will solve you problem.

Zeeshan Ahmed
  • 1,179
  • 2
  • 13
  • 30