Click here to Skip to main content
15,849,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am new to android, so need a little help in dialog box
I want to open web link in dialog box (my crazy experiment)

Here's the code I used --->
Java
public void alertcreate (View v)
    {
    	
    	AlertDialog alert = new AlertDialog.Builder(mcontext).create();
    	alert.setTitle("Hello");
    	alert.setMessage("Welcome");
    	    	
    	alert.setCanceledOnTouchOutside(true);
    	
    	WebView mWebView = (WebView)alert.findViewById(R.id.webView1);
    	String urlString= "http://www.google.com";
    	//mWebView.loadData(urlString,"Text/HTML","UTF-8");
    	mWebView.loadUrl(urlString);
    	mWebView.setWebViewClient(new WebViewClient(){
    		public boolean shouldOverrideUrlLoading(WebView view, String url) {
    			
    		    //Log.i(TAG, "Loading...");
    			// Intent i = new Intent(Intent.ACTION_VIEW);
                // i.setData(Uri.parse(url));
                // startActivity(i);
    			
    		       view.loadUrl(url);
    		       return true;
    		   }
    	});
    	
    	alert.show();
    }


I am not able to load the url in the dialog, please assist
Posted

1 solution

Try this one:
Java
public void alertcreate (View v){

        Dialog webViewDialog;
        webViewDialog = new Dialog(this);
        webViewDialog.setContentView(R.layout.webviewdialog);                

        webView = (WebView) webViewDialog.findViewById(R.id.wb_webview);
        webView.setScrollbarFadingEnabled(false);
        webView.setHorizontalScrollBarEnabled(false);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setUserAgentString("AndroidWebView");
        webView.clearCache(true);
        webView.loadUrl("http://google.com");
        
        webView.setWebViewClient(new WebViewClient(){
        	@Override
        	public boolean shouldOverrideUrlLoading(WebView view, String url) {
        		view.loadUrl(url);
        		return super.shouldOverrideUrlLoading(view, url);
        	}
        });
        

}
 
Share this answer
 
Comments
Sudendra 12-Sep-12 2:56am    
Thanks for the update

I think I should have setup a layout for dialog/alert
In this case its web view dialog/alert

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900