timoschloesser
timoschloesser

Reputation: 2802

android:text assign string resource & text

I would like to assign a string resource and some additional text to a textview. Is there a way to do this, without adding a second textview?

Something like this:

android:text="@string/DESCRIPTION"+": "

Upvotes: 0

Views: 1109

Answers (3)

Heiko Rupp
Heiko Rupp

Reputation: 30934

You can do similar with Context.getString(id,args...). As an Activity inherits from Context you can just directly use it in code.

values/strings.xml:

<string name="DESCRIPTION">Hello %s</string>

Activity:

String result = getString(R.string.DESCRIPTION,"world");

Upvotes: 1

Simon
Simon

Reputation: 14472

As far as I know, this can't be done. You will have to do it in code:

textViewTitle.setText(getResources().getString(R.string.DESCRIPTION) + ": ");

Upvotes: 0

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43088

Nope, text attribute doesn't support this. But you can use formatting api for your goals. Read here.

Upvotes: 0

Related Questions