Reputation: 551
I need to see inside an Android AlertDialog the content of a standard xml file.
Let's consider a standard xml page, that can be opened by a whatever internet browser, containing some formatted text, meaning with formatted with some bullets point, some white rows, etc... (see example below).
I'd like to see the content of the standard xml page inside an AlertDialog.
Normally I open an AlertDialog by the code:
AlertDialog.Builder myAlertDialogBuilder = new AlertDialog.Builder(this); myAlertDialogBuilder.setTitle(myTitle); myAlertDialogBuilder.setMessage(myMessage); myAlertDialogBuilder.setPositiveButton(myPositiveButton), dialogTipClickListener); myAlertDialogBuilder.show();
My target is to have, instead of the string "myMessage", the content of the xml file, with the formatting of xml file, meaning for formatting for example the same bullets point, the same white rows, etc... (see example below).
Just to be clear, I underline that the standard xml file is NOT an Android xml layout, but something like in the following:
<!DOCTYPE html>
<html>
<head>
<meta title="Manuale d'uso">
<meta charset="ANSI">
</head>
<body>
<a name="cap4"><h2><font color="blue">Utilizzo</font></h2></a>
<p>
L’utilizzo dell'applicazione è molto intuitivo.
</p>
<p>
Indicazioni di carattere generale sui colori ....:
<ul style="list-style-type:circle">
<li> Le icone in azzurro ..... </li>
<li> Le icone in colore grigio .... </li>
<li> Le icone in colore verde ..... </li>
<li> Le scritte in colore blu ..... </li>
</ul>
</p>
</body>
</html>
Thank you in Advance
Upvotes: 0
Views: 90
Reputation: 186
You need to create a custom alert window and use a Webview inside the alert window and load your xml file to that webview.
Another way is, you can create a String variable with html body and set this string variable to your myAlertDialogBuilder.setMessage(StringVariable) like:-
String xmlContentStr = Html.fromHtml("<p>L’utilizzo dell'applicazione è molto intuitivo.</p>");
I think its help you.
Upvotes: 3
Reputation: 1594
Try this code
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title here");
WebView wv = new WebView(this);
wv.loadData(<YOURHTML_STING>, "text/html; charset=UTF-8", null);
alert.setView(wv);
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alert.show();
Upvotes: 3