Kurt
Kurt

Reputation: 777

Changing the value of a button in Activity1 in the code of Activity2

I have an app with two activities -> activity1 and activity2. I want the user to be able to type text into an EditText in activity2, then on the click of a button in activity2 set the value of a button in activity1 to that text and then return to activity1.

What is the best approach to doing this?

Upvotes: 0

Views: 54

Answers (2)

Mohd Mufiz
Mohd Mufiz

Reputation: 2236

You can send some text with intent

In your activity

Intent intent=new Intent(context,Activity1.class)
intent.putExtra("buttonText",editText.getText().toString());
statActivity(intent);

and in your Activity1

in onCreate

Bundle bundle=getIntent().getExtras();

if(bundle!=null)
{
  String buttonText=bundle.getString("buttonText");
  button.setText(buttonText);
}

Upvotes: 1

Kumar Bibek
Kumar Bibek

Reputation: 9117

Start Activity2 for result. Set result from Activity2. And then in Activity's onCreate check the value, and set it.

http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)

There's a tutorial here.

http://developer.android.com/reference/android/app/Activity.html

Search for "Starting Activities and Getting Results"

Upvotes: 2

Related Questions