Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate 2 strings in android?

I am displaying a Error message in a Toast with strings.xml.

Like this mErrorMsgId=R.string.username_or_password_incorrectfull;

But now i need to concatenate the message with R.string.add_selfhosted_blog to avoid translation inconsistencies.

Read some similar questions but can't figure it out.

EDIT:

I want to concatenate nux_add_selfhosted_blog after the word tap in the username_or_password_incorrectfull string ...

<string name="username_or_password_incorrectfull">The username or password you entered is incorrect
 \- If you\'re a self hosted user, don\'t forget to tap **Add Self Hosted Site** and fill the URL field</string> 

<string name="nux_add_selfhosted_blog">Add self-hosted site</string>

How can i acheive this ??

like image 843
user3467240 Avatar asked Apr 03 '14 05:04

user3467240


1 Answers

You cannout concatenate R.string.username_or_password_incorrectfull with R.string.add_selfhosted_blog directly as they are not String instances as such but rather the resource id to the actual String in the strings.xml. You can get the 2 strings and then concatenate them normally.

Something like this:

String string1 = getResources().getString(R.string.username_or_password_incorrectfull);
String string2 = getResources().getString(R.string.add_selfhosted_blog);

String combined = string1 + string2;
like image 174
Rahul Avatar answered Sep 20 '22 01:09

Rahul