简体   繁体   中英

TextView showing R.java Resource IDs

I'm trying to display more than one thing in a single textview of my dialog using a + in between BUT when i do this it shows the resource ID of the 1st string and then it shows the 2nd string normally. Here's an excerpt of my code.

TextView text = (TextView)
dialog.findViewById(R.id.TextView01);
text.setText(R.string.aboutDialog + strVersion);

strVersion is a string variable that gets initialized before this. It shows the VersionName in the dialog.

So for example when the dialog is shown, instead of showing the contents of BOTH R.string.aboutDialog and strVersion it shows the R.java resource ID of R.string.aboutDialog .

Example of what it looks like:

    [About This App]
    2131034115 
    Version: 1.5-debug
      [OK]

The 2131034115 seems to be the resource ID of the R.string.aboutDialog

What can I do to fix this?

change

text.setText(R.string.aboutDialog + strVersion);

to

text.setText(getResources().getString(R.string.aboutDialog) + strVersion);

Try concatenating the strings first into a different string - and then setting it in setText().

concatenate two strings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM