Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to display multiple images one after another in some time interval

    • 0
    • 2
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 2.18k
    Comment on it

    Sometimes we need to display ads in our application.To display the multiple images one after another in some time interval write the following code:

    1. Create a customTimerTask class that extends the TimerTask class
    public class customTimerTask extends TimerTask
    {
        Context mycontext;
        int i =0;
        public customTimerTask(Context c) {
            mycontext=c;
        }
    
        @Override
        public void run() {
    
            advanceSearch.runOnUiThread(new Runnable() {
    
                public void run() {
                    // Display the images
                    adImage.setTag(ServerUrl.BASE_SERVER_URL+ServerUrl.AD_UOLAOD_URL+imageArray.get(i).getImagePath());         
                    imageLoader.DisplayImage(ServerUrl.BASE_SERVER_URL+ServerUrl.AD_UOLAOD_URL+imageArray.get(i).getImagePath(), advanceSearch, adImage);
                    i++;
                    if(i >= imageArray.size()){
                        i = 0;
                    }
                }
            });
        }
    }

    2. Then write the below line of code where you want to display images after getting the array of images

    if(imageArray != null && imageArray.size() > 0)
    {
        Timer timer=new Timer();
        /*
        Schedule a task for repeated fixed-rate execution after a specific delay has passed.
        Parameters
        task  the task to schedule. 
        delay  amount of time in milliseconds before first execution. 
        period  amount of time in milliseconds between subsequent executions. 
        */
        timer.scheduleAtFixedRate(new customTimerTask(advanceSearch),4000,4000);
    }

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: