Reputation: 2613
How can I get text from the strings.xml file into my .setmessage?
show = new AlertDialog.Builder(mContext).setTitle("moria")
.setMessage("R.string.erroroik")
.setPositiveButton("OK", null).show();
Upvotes: 5
Views: 14877
Reputation: 338
Solution 1
Context context;
show = new AlertDialog.Builder(mContext).setTitle("moria")
.setMessage(context.getString(R.string.erroroik))
.setPositiveButton("OK", null).show();
Solution 2
show = new AlertDialog.Builder(mContext).setTitle("moria")
.setMessage(getString(R.string.erroroik))
.setPositiveButton("OK", null).show();
Upvotes: 3
Reputation: 73484
The ids in the xml resource files are actually integer values not strings.
show = new AlertDialog.Builder(mContext).setTitle("moria")
.setMessage(R.string.erroroik)
.setPositiveButton("OK", null).show();
Upvotes: 3
Reputation: 7197
You can access it through context, depending where exactly this DialogBuilder is, it can be
context.getString(R.string.erroroik);
or
this.getString(R.string.erroroik);
Take a look at String Resources for more information.
Upvotes: 9
Reputation: 26925
Use R.string.yourText
without ""
since R.string.yourText
is referring to an int
declared as static
in your R.java
.
Upvotes: 6
Reputation: 76458
show = new AlertDialog.Builder(mContext).setTitle("moria")
.setMessage(R.string.erroroik)
.setPositiveButton("OK", null).show();
Done
Upvotes: 3