Reputation: 11
i got class Team and object name. I want to display the name in another activity in textView and i don't know how to do it. Can you help me? my code of class and object:
public class DruzynyStatActivity extends ActionBarActivity {
public class Team
{
public String name;
}
...
public void cracovia(View view)
{
Intent intent = new Intent(this, CracoviaActivity.class);
startActivity(intent);
Team cracovia= new Team();
cracovia.name="Cracovia";
}
Upvotes: 0
Views: 695
Reputation: 5227
You can pass the data over the intents. The code you are using on the button click is starting the next activity with passing parameter as intent.
Intent intent = new Intent(this, CracoviaActivity.class);
intent.putExtra("key","value");
startActivity(intent);
Now on the another activity you can get this intent and the value by the key. as-
Intent intent=getIntent()
String received_value=intent.getStringExtra("key");
You can also add a Bundle object on the intent if you want to deal with more no of data.
Upvotes: 1
Reputation: 184
This should do it:
public void cracovia(View view)
{
Intent intent = new Intent(this, CracoviaActivity.class);
Team cracovia= new Team();
cracovia.name="Cracovia";
name = cracovia.name;
intent.putExtra("teamName", name);
startActivity(intent);
}
Unless I am misunderstanding.
Upvotes: 0
Reputation:
You can use putExtra(..., ...)
to pass values between activities.
See this other StackOverflow post
Upvotes: 1