ANDROID

Hagi 2011. 4. 19. 17:29

핵심 참고 : http://holamiamor.tistory.com/274

               http://nuninaya.tistory.com/536


==================================================================================================


public class WebViewingStroyboard extends Activity {
    /** Called when the activity is first created. */
   
    private WebView _webview;   
   
    private class HelloWebViewClient extends WebChromeClient {
        //javascript의 alert과 confirm을 인식하기 위해서는 onJsAlert과 onJsConfirm 메서드가 있어야 합니다.
        @Override
        public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result){
           new AlertDialog.Builder(view.getContext())
              .setTitle("타이틀")
              .setMessage(message)
              .setPositiveButton(android.R.string.ok,
                    new AlertDialog.OnClickListener(){
                       public void onClick(DialogInterface dialog, int which) {
                          result.confirm();
                       }
                    })
              .setCancelable(true)
              .create()
              .show();

           return true;
        };
        @Override
        public boolean onJsConfirm(WebView view, String url, String message, final android.webkit.JsResult result){
           new AlertDialog.Builder(view.getContext())
              .setTitle("타이틀")
              .setMessage(message)
              .setPositiveButton(android.R.string.ok,
                    new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                          result.confirm();
                       }
                    })
              .setNegativeButton(android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                          result.cancel();
                       }
                    })
              .create()
              .show();

           return true;
        };


    }
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        _webview = (WebView) findViewById(R.id.webview);
        _webview.setWebChromeClient(new HelloWebViewClient());
        _webview.getSettings().setJavaScriptEnabled(true);
        _webview.loadUrl("http://www.maroon.pe.kr/webmaster/java/htm/capevent2.htm");  
    }
}