How to load URL consecutively one by one

后端 未结 6 1938
野趣味
野趣味 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:50

    I tried to simulate and came up with the following:

    package com.mywebslider;
    
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.CountDownTimer;
    import android.view.KeyEvent;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class WebSliderActivity extends Activity {
    
        TextView number;
        WebView mWebView;
        CountDownTimer mTimer;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
    
            number = (TextView) findViewById(R.id.number);
            mTimer=new CountDownTimer(15000, 1000) {
    
             String[] myArray={"http://www.upc.nl/","http://www.google.com","http://www.quickspot.nl"}; 
    
    
                int currentIndex=0; 
                public void onTick(long millisUntilFinished) {
    
                    number.setText("seconds remaining: " + millisUntilFinished / 1000);
                }
                 //code comment start
                 // i think this part could be written better
                 // but it works!!!
                public void onFinish() {
                    if (currentIndex

    Beside the fact this works, the array loop can be done better. main.xml should read:

    
    
    
        
    
    
    
    
    

    The output will make a 50/50 screen. One is for the WebView and the other half shows a counter in a TextView.

提交回复
热议问题