Mr.AwfulAtProgramming Mr.AwfulAtProgramming - 1 year ago 87
Java Question

Passing string from spinner to second activity

I'm building an app in which the first activity contains a spinner with strings "Red", "Yellow", "Blue" and "Green". When the user selects a spinner item, the second activity's background will be that color. I'm having issues with passing that value from the MainActivity class to the Display class.

Answer Source

In case you wonder how to retrieve the spinner value :

String pickedColor = yourSpinner.getSelectedItem().toString();

In your first Activity, when building intent do something like :

Intent intent = new Intent(MainActivity.this, DisplayActivity.class);
intent.putExtra("COLOR_KEY", pickedColor);

Then in your second activity :

String color = getIntent().getStringExtra("COLOR_KEY");

Then do whatever you need :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download