2016-02-20 193 views
1

我是新來的android和我試圖加載多個文件從一個XML Android WebView上的保存說15秒後。我得到的大多數答案只是在第一頁和最後一頁之間沒有任何內容......請協助。謝謝...Android WebView加載多個URL

+0

請詳細解釋您正在嘗試做什麼。你想每隔15秒在webview中加載另一個URL?你指的是哪些網頁? – Zackline

+0

是的...我有webview加載一個URL。 15秒後,webview將加載一個新的URL作爲數組或其他任何最佳選項存儲。這些URL指向DropBox上的文檔。 – ErickPaul

回答

0

幾個月後,我終於找到了解決辦法。

//Remember to declare your variables 

WebView mWebView2; 
TextView number; 
CountDownTimer mTimer; 

//Inside the onCreate Method of the Activity 

//Text view to let user know count down before next URL is loaded. 15 seconds 
number = (TextView) findViewById(R.id.numberportal); 
mTimer = new CountDownTimer(15000, 1000) { 

     String[] myArray = {"https://example.gif", "https://example.gif","https://example.gif", "https://example.gif","https://example.gif","https://example.gif"}; 


     int currentIndex = 0; 

     public void onTick(long millisUntilFinished) { 

      number.setText("" + millisUntilFinished/1000); 
     } 

     //code comment start 
     // i think this part could be written better 
     // but it works!!! 
     public void onFinish() { 
      if (currentIndex < myArray.length) { 

       mWebView2.loadUrl(myArray[currentIndex]); 
       currentIndex++; 
      } else { 
       currentIndex = 0; 
       if (currentIndex < myArray.length) 

        mWebView2.loadUrl(myArray[currentIndex]); 
       currentIndex++; 
       mTimer.start(); 
      } 

      mTimer.start(); 

     } 
     //code comment end 
    }; 

    mTimer.start(); 
    mWebView2 = (WebView) findViewById(R.id.webView); 
    mWebView2.getSettings().setJavaScriptEnabled(true); 
    //URL of first image 
    mWebView2.loadUrl("https://dl.dropbox.com/firstimage.png"); 
    mWebView2.setWebViewClient(new WebSliderWebViewClient() { 
     @Override 
     public void onPageFinished(WebView view, String url) { 
      super.onPageFinished(mWebView2, url); 

     } 

     @Override 
     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 

     } 
    });