-2

I am trying to concatenate two strings like the below Method.I Referred from dynamic String using String.xml?

String incorrect = getResources().getString(R.string.username_or_password_incorrect);
mErrorMsgId = String.format(getResources().getString(R.string.username_or_password_incorrectfull), incorrect);

it returns error: incompatible types required: int found: String

EDIT

I need to replace the %1$s in the below string with this string R.string.username_or_password_incorrect

'<string name="username_or_password_incorrectfull">The username or password you entered is incorrect \- If you\'re a self hosted WordPress.org user, don\'t forget to tap %1$s and fill the URL field</string>'

How to solve this ?

Community
  • 1
  • 1
Arulnadhan
  • 923
  • 4
  • 17
  • 46

2 Answers2

0

I'm not sure it's possible. If it is, I'm not aware of it.

What you could do, is something like this; Create 2 string, one that contains The username or password you entered is incorrect \- If you\'re a self hosted WordPress.org user, don\'t forget to tap and another one with and fill the URL field

and then contcatenate it with the 'incorrect' variable.

String a = getResources().getString(R.string.username_or_password_incorrectfull);
String b = getResources().getString(R.string.username_or_password_incorrectfull2);
String mErrorMsgId = a + incorrect + b;

Note: A better approch would be to use the StringBuilder class to concatenate different variables types, but for the sake of example, this should do.

La bla bla
  • 8,558
  • 13
  • 60
  • 109
0

This is very confusing, why would have mErrorMsgId as an int? change this to a String and it won't error anymore:

so change

private int mErrorMsgId;

to

private String mErrorMsgId;
Dreagen
  • 1,733
  • 16
  • 21