Android WebView加载多个URL

时间:2016-02-20 15:18:39

标签: android url webview

我是Android新手,我试图在15秒后在XML Android WebView上从dropbox加载多个文件。我得到的大多数答案只加载了第一页和最后一页之间没有任何内容...请帮助。谢谢......

1 个答案:

答案 0 :(得分: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) {

        }
    });