How to load URL consecutively one by one

后端 未结 6 1919
野趣味
野趣味 2021-01-06 03:13

I want to load URL one by one.I used String array to store the URL.My requirement is that if the webview loads the first url it should print the msg \"page started\" when p

6条回答
  •  独厮守ぢ
    2021-01-06 03:36

    You can use a queue to hold the urls that are to be loaded one after another.

    Queue mQueue = new LinkedList();
    ...
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        mQueue.add("http://url1");
        mQueue.add("http://url2");
        mQueue.add("http://urln");
        ...
        String url = mQueue.remove();
        mwv.loadurl(url);
    }
    ...
    public class myweb extends WebViewClient{
        @Override       
        public boolean shouldOverrideUrlLoading(WebView view, String url) { 
            System.out.println("LOADING");
    
            return false;
        }
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            System.out.println("PageStarted: " + url);
        }
    
        @Override   
        public void onPageFinished(WebView view, String url){
            System.out.println("PageFinished: " + url);
            String url = null;
            url = mQueue.remove();
            if (url != null) {
                view.loadUrl(url);
            }
        }
    }
    

提交回复
热议问题