0

For a school project I want to save the string above the button ('kopen'), after clicking on that button. The textviewID for that string is 'textViewMenu'. The buttonID is 'buttonKopen'

After saving it, I want to display the string in a new activity.

If i press 3 buttons, I need to display all three strings in my new activity. The name of that new activity is 'MijnBonnen'.

shop layout

I have no errors, I'm just looking for some help to start Any help is welcome!

Meindert Stijfhals
  • 355
  • 1
  • 3
  • 12

1 Answers1

1

You can use an Arraylist to store the strings

ArrayList<String> list = new ArrayList<String>();

Then on every button click add the text to to the arraylist like

public void onClick(View v) {

String clickedText;

switch(v.getId())
{
   case R.id.your_1st_button_id:
   clickedText=your_textView.getText().toString();
   break;
   case R.id.your_2nd_button_id:
   clickedText=your_1st_textView.getText().toString();
   break;
   case R.id.your_3rd_button_id:
   clickedText=your_3rd_textView.getText().toString();
   break;

 }

  list.add(clickedText);

}

After that send the arraylist as extra with Intent using

 Intent i=new Intent(this,Second.class);
 i.putStringArrayListExtra("list", ar);
 startActivity(i);

Now in the second activity get the arraylist like

ArrayList<String> ar1=getIntent().getExtras().getStringArrayList("list");

Now from second activity you can access all arraylist data with a for loop

 for (String s : ar1){
  Log.d("My array list content: ", s);
 }
Community
  • 1
  • 1
Zahan Safallwa
  • 3,880
  • 2
  • 25
  • 32