Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:38:14+00:00 2026-06-07T23:38:14+00:00

I followed this topic auto scroll a Gallery widget to create a Gallery auto

  • 0

I followed this topic auto scroll a Gallery widget to create a Gallery auto scroll from left to right every 5 seconds. Here’s my Gallery:

public class MyBannersGallery extends Gallery {

private Handler handler;

public MyBannersGallery(Context ctx, AttributeSet attrSet) {
    super(ctx, attrSet);
    handler = new Handler();
    postDelayedScrollNext();
}

private void postDelayedScrollNext() {
    handler.postDelayed(new Runnable() {
        public void run() {
            postDelayedScrollNext();
            onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
        }
    }, 5000);

}

private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
    return e2.getX() > e1.getX();
}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    int kEvent;
    if (isScrollingLeft(e1, e2)) {
        kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
    } else {
        kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
    }
    onKeyDown(kEvent, null);
    return true;
}

}

When it scrolled to the end of my Gallery, it stopped. Now I want to detect if my Gallery is scrolled to the end or not. And if it does, scroll back to the left to the first item. What should I edit my class to archive this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:38:17+00:00Added an answer on June 7, 2026 at 11:38 pm

    Gallery extends from AdapterView, therefore you can use the method ‘getSelectedItemPosition()’ to determine where the current image index is. So perhaps something like this will work?

    private void postDelayedScrollNext() {
        handler.postDelayed(new Runnable() {
            public void run() {
                // check to see if we are at the image is at the last index, if so set the 
                // selection back to 1st image.
                if (getSelectedItemPosition() == getCount() - 1) {
                   setSelection(0);
                   postDelayedScrollNext();
                   return;
                }
                postDelayedScrollNext();
    
                onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
            }
        }, 5000);
    
    }
    

    Of course, this is just an quick hack. If you want nice animation where the gallery scrolls nicely back to the first item, then you have to do additional work, but the idea is the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed this tutorial on creating a simple rss reader... http://www.kieranmcgrady.com/blog/2012/4/25/tutorial-how-to-create-a-simple-rss-reader-for-ios.html The problem is
Followed this question about delayed_job and monit Its working on my development machine. But
I followed this tutorial . But whenever I try to log in with my
I followed this video tutorial for detecting memory leaks using Instruments with Xcode 4.3.2.
I followed this link to gzip my php driven website It's working fine but
I followed this tutorial to implement facebook into my application. All I want is
I followed this post http://neurochannels.blogspot.com/2010/05/how-to-run-r-code-in-matlab.html , to install R(D)Com server in order to call
I followed this tutorial http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html I wrote the manifest File giving all the permissions
I followed this tutorial http://stevejenkins.com/blog/2011/08/how-to-install-apc-alternative-php-cache-on-centos-5-6/ to install apc on my centos vps hosting but
I followed this tutorial to get started using Android host api with an Arduino

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.