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 ?
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.
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;
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.