Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a dialog with content from a string?

Is it possible to make a dialog with content from a string defined in your OnCreate? Because the only way to define the content of the dialog, which I could find, is with text or a string defined in values/strings.xml like this:

builder.setMessage(R.string.dialog_fire_missiles)

I hope there is someone who can help me, please tell me if my question is clear enough.

like image 454
user1946633 Avatar asked Dec 09 '22 18:12

user1946633


2 Answers

use getString method of Context to get String from strings.xml:

builder.setMessage(Your_Activity.this.getString(R.string.dialog_fire_missiles))
like image 112
ρяσѕρєя K Avatar answered Dec 11 '22 07:12

ρяσѕρєя K


Just use:

builder.setMessage("Your Message")

There are two setMessage() methods, one for accepting a CharSequence, and one for accepting an R.string.*.

like image 39
Raghav Sood Avatar answered Dec 11 '22 06:12

Raghav Sood