Skip to content Skip to sidebar Skip to footer

How Do I Set Text Of Textview To A String Resource? (java For Android)

I would like to change the text of a TextView component to another text, that I have already created in strings.xml. When the app starts, the text shown is stored in strings.xml, u

Solution 1:

Because You have concatted String resource id with normal String help So its worked as a String. You have to get first resource string from android resource and then need to concat with local String variable, like,

help.setText(getResources().getString(R.string.help)+help);

As I doubt, if you are looking for dynamically String id, You want String resource id with already exist id and '0' append to it then get int resource id from String using..

int resourceId = this.getResources().getIdentifier("@string/help" + help, "string", this.getPackageName());

and then

help.setText(resourceId);

Solution 2:

Try this

String help = "0";
final TextView tvHelp = (TextView) findViewById(R.id.help);
String yourString = getResources().getString(R.string.help);
tvHelp.setText(yourString +help)

Solution 3:

I believe that strings.xml resource file content cannot be edited during runtime. now i am assuming u have the following on your strings.xml file

<resources><stringname="app_name">Application Name</string><stringname="help0">Text1</string><stringname="hellp00">Text2</string></resources>

if u want to change the text on your TextView (id=@+id/textview) from the value stored as "help0",to value stored in "help00" use the following code:

Stringtext= getString(R.string.help00);
TextView myTextView = findViewById(R.id.textview);
myTextView.setText(text);

Post a Comment for "How Do I Set Text Of Textview To A String Resource? (java For Android)"