2017-12-29 36 views
0

私は、ビューページとボタンを持つactivtyを持っています。以下は、それぞれの必要なパラメータ(viewpagerデータ)、とOutletMapWebView活動への移動ボタンのonclickのWebview初めての読み込み

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    pd = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new ProgressDialog(MainActivity.this) : new ProgressDialog(MainActivity.this, android.R.style.Theme_Holo_Panel); 


    webView = (WebView) findViewById(R.id.outletMapWebView); 

    // String MAP_URL = "<html><body><iframe width='100%' height='100%' frameborder='0' style='border:0' src='https://www.google.com/maps/embed/v1/directions?key=AIzaSyD7mjSU3lSzYHgGcUglDog9cxLNjZDq_68&origin=12.9312987,77.5154981&destination=217 East Coast Road, Singapore&mode=driving'></iframe> </body></html>"; 
    String jala_kayu = "<html><body><iframe width='100%' height='100%' frameborder='0' style='border:0' src='https://www.google.com/maps/embed/v1/directions?key=AIzaSyD7mjSU3lSzYHgGcUglDog9cxLNjZDq_68&origin=12.9313121,77.5154951&destination=269 Jalan Kayu, Singapore&mode=driving'></iframe> </body></html>"; 
    webView.setWebViewClient(new myWebClient()); 
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.getSettings().setBuiltInZoomControls(true); 
    webView.getSettings().setSupportZoom(true); 
    webView.loadDataWithBaseURL(null, jala_kayu, "text/html", "UTF-8", null); 

} 

public class myWebClient extends WebViewClient 
{ 
    @Override 
    public void onPageStarted(WebView view, String url, Bitmap favicon) { 
     pd.setMessage(""); 
     pd.setIndeterminate(true); 
     pd.setCanceledOnTouchOutside(false); // updated jul 3 
     pd.setCancelable(true); // updated jul 3 
     if (!isFinishing()) // updated jul 3 
      pd.show(); 
     super.onPageStarted(view, url, favicon); 
    } 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     Log.w("mCurrentUrl",""+url); 
     view.loadUrl(url); 
     return true; 
    } 

    // Here the page loading will stop so dismiss the ProgressDialog 
    public void onPageFinished(WebView view, String url) { 
     // this is what we should do 
     webView.invalidate(); 
     pd.dismiss(); 
    } 
} 

@Override 
public void onBackPressed() { 
    System.gc(); 
    super.onBackPressed(); 
} 

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) 
{ 
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { 
     webView.goBack(); 
     webView.invalidate(); 
     return true; 
    } 
    return super.onKeyDown(keyCode, event); 
} 

コードのコードが完全に最初のクリックのために働いている、WebViewの内部グーグルマップが開きますが、その後の予定でviewpagerを変更して、ボタンをクリックすると再び表示されます。 Webviewは白い空白の画面を表示します。私はバンドルされたすべてのデータをチェックしました。ブラウザのマップURLをチェックしました。できます 。 Webviewの内部では動作していません。私は、初めて初めてWebビューをリフレッシュすることに関連するものがあると思います。助けてください 。 。事前におねがいします。

+0

Lolipop以下でチェックしてもうまくいきますが、ロリポップバージョンは機能しません。ありがとうございます –

答えて

0

これをコードに追加します:webView.getSettings()。setDomStorageEnabled(true);

+0

返事ありがとうございます、しかしそれは働かなかった –

関連する問題