-2

These picture show what I am thinking about.

enter image description here

btn_view_cart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                activity2 object = new activity2();
                Intent MainActivity = new Intent(MainActivity.this,activity2.class);
                Bundle b = new Bundle();
                b.putString(object.temp, "");
                MainActivity.putExtras(b);
                startActivity(MainActivity);
                finish();

            }
        });

here is my view cart code

Here is my second activity. And I need to display the name, description, price, quantity and the total of all the orders whenever the user clicks the add to cart button.

I need to transfer the Name, Description, Price and Quantity to a second activity using intent, and put the data in a Listview. How can I achieve this?

  • I'm voting to close this question as off-topic because this is a link-only question without any effort by the asker to ask a proper question. – Lajos Arpad Aug 26 '17 at 12:49
  • i am a new user. My apologies. – Patrick Diño De Guzman Aug 26 '17 at 12:52
  • No problem, I have edited your question to at least make sure something can be seen, but we need a specific textual description of your problem as well, so please edit your question by clicking on the edit link below the android tag. – Lajos Arpad Aug 26 '17 at 12:55
  • 1
    I have edited my question. – Patrick Diño De Guzman Aug 26 '17 at 13:00
  • Very good! Have you tried anything so far? If so, please show us what have you tried and how did the attempt(s) fail. We also need a specific question, like: "I need to transfer the Name, Description, Price and Quantity to a second activity using intent, and put the data in a Listview. How can I achieve that?" – Lajos Arpad Aug 26 '17 at 13:04
  • I have not tried anything so far, but I have made the View cart button work. The only thing I need to complete the project is when I click the "Add to Cart" button, the data of the Name, Description, Price and Quantity will be transferred to a list view in the second activity. How can I achieve that? Thank you. – Patrick Diño De Guzman Aug 26 '17 at 13:11
  • I am not an Android expert, but I can see the problems in your question. I will not give you an answer, but will help you modify this question into a state which is answerable for Android guys. If you try something, even if you fail, your question will draw more sympathy. If you show us how your View cart button was implemented, then we can see that you actually tried something. Your question in its current state will draw many down-votes and no answers. With some small changes you can raise its quality. – Lajos Arpad Aug 26 '17 at 13:27
  • How can I add a picture of what I have tried so far? – Patrick Diño De Guzman Aug 26 '17 at 13:35
  • You should add the code of what you have tried so far. – Lajos Arpad Aug 26 '17 at 13:37
  • I have added the code. – Patrick Diño De Guzman Aug 26 '17 at 13:43
  • Possible duplicate of [How do I get extra data from intent on Android?](https://stackoverflow.com/questions/4233873/how-do-i-get-extra-data-from-intent-on-android) – Beloo Aug 26 '17 at 15:58

3 Answers3

1

in MainActivity:

Intent intent = new Intent(MainActivity.this, CartActivity.class)
intent.putExtra("quantity", quantity);
intent.putExtra("price", price);
intent.putExtra("description", description);
startActivity(intent);

in the onCreate method of CartActivity:

String name = getIntent().getStringExtra("name");
String description = getIntent().getStringExtra("description");
double price = getIntent().getDoubleExtra("price", 0);
int quantity = getIntent().getIntExtra("quantity", 0);

Must use the same keys when you put and retrieve each value

Anonymous
  • 4,470
  • 3
  • 36
  • 67
0

Use Intent to transfer data.

But for transfer list of data use Bundle and Synchronise your POJO class.

acdcjunior
  • 132,397
  • 37
  • 331
  • 304
Vijay Chaudhary
  • 228
  • 2
  • 12
0

You can also use putStringArrayListExtra() and getStringArrayListExtra() to put all your orders in a list. in you calling method:

ArrayList<String> orders = new ArrayList<>();
        orders.add(whatever1);
        orders.add(whatever2);
        //....//
        orders.add(whateverN);

        Intent intent = new Intent(MainActivity.this,Next.class);
        intent.putStringArrayListExtra("ORDERS",orders);

OnCreate of the Next class add:

ArrayList<String> orders = Intent.getIntent().getStringArrayListExtra("ORDERS");
Aniruddha Bera
  • 399
  • 6
  • 19