-1

I have a list of products (dynamic listview), each listview's row implement onclicklistener to take me to the product details showed in three textview. Now I would to take the text from those textviews by getText.toString and populate a new Listview in another activity through a button click.

i.e.: SubmenuActivity (listview) -> ProductActivity (product details){Button add.setOnClickListener (pass the data to CartActivity populating the listview)}.

I know I need a cart application, tried to look at some samples but no one it's for me.

Any help or suggestion would be much appreciated. Thanks in advance.

Nonjoe
  • 121
  • 2
  • 3
  • 12

1 Answers1

1

When you start the Product activity, you do it using something like

Intent intent = new Intent(this, ProductActivity.class);
startActivity(intent);

To transmit data from one activity to the other, put the data in the intent

Intent intent = new Intent(this, ProductActivity.class);
intent.putExtra(EXTRA_MESSAGE, message);
intent.putExtra(OTHER_INFO, otherInfo);
startActivity(intent);

and use it in your ProductActivity like this

Intent intent = getIntent();
String message = intent.getStringExtra(EXTRA_MESSAGE);
String otherInfo = intent.getStringExtra(OTHER_INFO);

where EXTRA_MESSAGE and OTHER_INFO are constants in your app.

Also, here is a nice step by step from Google about this: http://developer.android.com/training/basics/firstapp/starting-activity.html

Andrei Tudor Diaconu
  • 2,157
  • 21
  • 26
  • My fault. I know how to basically use intent extra but I would populate a listview adding elements from few activities clicking on the add button. Finally, open the CartActivity manually, I would to see the listview populated with all the arrays I've created clicking 'add' in the 'multiple' ProductActivity. – Nonjoe Mar 23 '15 at 12:04
  • 1
    I finally understood what you want to do. You need to store all the "added" products in a common place. Since I see you are learning Android, you can try and store your products in the Application class, so you can access them in all activities. [Here's](http://stackoverflow.com/questions/4208886/using-the-android-application-class-to-persist-data) more about this – Andrei Tudor Diaconu Mar 23 '15 at 12:30
  • Yes, I'm learning Android and, yes you understood it right. Thanks for the suggestion, it's my case. – Nonjoe Mar 23 '15 at 12:33