• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps changing a string of textview

basilyos

Lurker
Jun 11, 2013
2
0
Hello all i'm working on an android application with 2 activities.
The first activity contains 2 buttons ( btn1 , btn2).
The second activity contains a textview and a back button.
In the string.xml I have two strings ( str1, str2).
What I want is when I click on btn1 the second activity should open and the textview will show the first string str1 and when I click on the second button btn2 the second activity open and the same textview show the second string str2

I'm a newbie I hope that you will help me
 
Try something like this in your onClick event for buttons:

Intent intent = new Intent(this, ActivityName.class);
String message = textView.getText().toString();
intent.putExtra("text", Resources.getText(R.string.str1); //in button2 R.string.str2
startActivity(intent);

In your text view Activity's onCreate do something similar to the following:

TextView textView = (TextView) relativeLayout.findViewById(R.id.textView1);
Bundle b = new Bundle();
b = getIntent().getExtras();
textView.setText (b.getString("text"));

Good luck.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones