Get data from strings.xml

How can I get text from strings.xml in my .setmessage?

show = new AlertDialog.Builder(mContext).setTitle("moria")
        .setMessage("R.string.erroroik")
        .setPositiveButton("OK", null).show();
+5
source share
6 answers

You can access it through the context, depending on where exactly this DialogBuilder is, it can be

context.getString(R.string.erroroik);

or

this.getString(R.string.erroroik);

See String Resources for more information.

+9
source

Use R.string.yourTextwithout "", as it R.string.yourTextrefers to int, declared as staticin yours R.java.

+6
source
show = new AlertDialog.Builder(mContext).setTitle("moria")
                    .setMessage(R.string.erroroik)
                            .setPositiveButton("OK", null).show();

+3

xml , .

show = new AlertDialog.Builder(mContext).setTitle("moria")
                    .setMessage(R.string.erroroik)
                            .setPositiveButton("OK", null).show();
+3

1

Context context;
show = new AlertDialog.Builder(mContext).setTitle("moria")
    .setMessage(context.getString(R.string.erroroik))
    .setPositiveButton("OK", null).show();

2

show = new AlertDialog.Builder(mContext).setTitle("moria")
    .setMessage(getString(R.string.erroroik))
    .setPositiveButton("OK", null).show();
+3

x = getResources(). getString (R.string.xxxxx);

+1

All Articles