1

I am trying to display 'WebView' in 'AlertDialog'. For that I referred one of the question posted here: Displaying WebView in AlertDialog It successfully opens the dialog window. But I dont know some how its not showing the web content. This is my 'print_webview' file, which I am inflating in AlertDialog window:

'<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@+id/root">
  <WebView
  android:id="@+id/dialog_webview"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>    
</LinearLayout>'

This is my Java file:

'public class CloudPrintTest extends Activity {
    static final int GOOGLE_CLOUD_PRINT_DIALOG = 1; //dialog ID for google cloud print

    /** Called when the activity is first created. */
    Button printButton;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        printButton = (Button)findViewById(R.id.button1);
        printButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //startActivity(new Intent(CloudPrintTest.this,PrintDialog.class));
                showDialog(GOOGLE_CLOUD_PRINT_DIALOG);
            }
        });
    }
    @Override
    protected Dialog onCreateDialog(int id) {
        // TODO Auto-generated method stub
        switch(id){
        case GOOGLE_CLOUD_PRINT_DIALOG:
            //LayoutInflater layoutInflator = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //final View dialogLayout = layoutInflator.inflate(R.layout.print_webview, null);
            LayoutInflater inflater = LayoutInflater.from(CloudPrintTest.this);
            View alertDialogView = inflater.inflate(R.layout.print_webview, null);
            WebView myWebView = (WebView)alertDialogView.findViewById(R.id.dialog_webview);
            myWebView.getSettings().setJavaScriptEnabled(true);
            myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
            myWebView.setWebViewClient(new PrintTestWebViewClient());
            myWebView.loadUrl("http://www.google.com/");
            AlertDialog.Builder builder = new AlertDialog.Builder(CloudPrintTest.this);
            builder.setView(alertDialogView);
            builder.setTitle("Google Cloud Print");
            builder.setCancelable(true);
            AlertDialog printDialog = builder.create();
            return printDialog;
        }
        return null;
    }

    private class PrintTestWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }   
    }
}'

I have tried all the possible ways, but didnt get the result. Please help. Regards

Community
  • 1
  • 1
YuDroid
  • 1,599
  • 5
  • 22
  • 44
  • 1
    http://stackoverflow.com/questions/5563957/show-soft-keyboard-in-alertdialog-with-a-webview-inside-android – Mehul Jun 06 '12 at 12:26

1 Answers1

0

What i would suggest is you creating an activity.

And when you register it in your manifest. Give it the Dialog look with

<activity android:theme="@android:style/Theme.Dialog">
coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
  • I am not starting any activity as you can see I have commented the code 'startActivity(...)'. So there isn't any need to declare the above tag in manifest file. – YuDroid Sep 23 '11 at 11:40