0

Hello guys I have created a listview on second activity and I have three button on main activity .on click of each button it will display a listview with diffrent names in second activity. I dont how to pass a string array through intent and display in a listview.

MAIN ACTIVITY

String []str={"hello","world"};
String []str2={"display","text"};
String [] str3={"android","programming"};

Intet intent=new Intent  (this,Second activity. class);
intent.putExtra("stringA",how to pass the string array here)
startActivity  (intent);
2
  • You should probably add some Codesnippets or further explanations. Currently the answer would be like "As a parameter". Commented Jul 13, 2017 at 11:35
  • This will help you: stackoverflow.com/a/11340842/5110536 Commented Jul 13, 2017 at 11:39

2 Answers 2

1
String []str={"hello","world"};
Bundle b = new Bundle();
b.putStringArray("key", str);
Intent i = new Intent(context, YourActivity.Class);
i.putExtras(b);

then to get from your second activity

Bundle data = this.getIntent().getExtras();
String[] array = data.getStringArray("key");
Sign up to request clarification or add additional context in comments.

Comments

0

On MainActivity Button Click you call this

Bundle bundle=new Bundle();
bundle.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(ActivityA.this, ActivityB.Class);
i.putExtras(bundle);

to read in SecondActivity call this.

Bundle bundle=this.getIntent().getExtras();
String[] array=bundle.getStringArray(key);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.