9

I have an application where I need to load a small webpage inside of webview. The webview needs to load up inside a dialog. I've tried to implement it; but everytime an empty dialog loads up and seems to have no content inside it. The code i've used is below

Uri uri = Uri.parse(item.getLink());
Dialog dialog = new Dialog(this);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.webviewdialog, null);
dialog.setContentView(v);
dialog.setCancelable(true);
WebView wb = (WebView) v.findViewById(R.id.webView1);
wb.loadUrl(uri.toString());
dialog.show();

I've also tried putting in urls directly inside loadUrl, but I get the same issue.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Avinash
  • 174
  • 1
  • 1
  • 8

1 Answers1

15

Try this:

    WebView webView = new WebView(this);
    webView.loadUrl("http://www.google.com/");
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setView(webView);
    dialog.setPositiveButton("Okay", null);
    dialog.show();
James McCracken
  • 15,488
  • 5
  • 54
  • 62