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

  • SEARCH
  • Home
  • 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 8169477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:51:20+00:00 2026-06-06T20:51:20+00:00

I’m using a gallery in my project in which I have added four images

  • 0

I’m using a gallery in my project in which I have added four images and I want it to be infinite from both right side and left side. How do I accomplish 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-06T20:51:21+00:00Added an answer on June 6, 2026 at 8:51 pm

    The main idea is that in your getView method, you have to use

    position = position % imagesArray.length;
    if (position < 0)
        position = position + imagesArray.length;
    

    imagesArray is the array that holds the images in your res folder. For example:

    public class CircularGallery extends Activity {
    /** Called when the activity is first created. */
    private Integer[] imagesArray = { R.drawable.picture1, R.drawable.picture2, R.drawable.picture3, R.drawable.picture4, R.drawable.picture5, R.drawable.picture6 , R.drawable.picture7   }; 
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        Gallery g = (Gallery) findViewById(R.id.gallery); 
        g.setAdapter(new ImageAdapter(this)); 
    
        g.setOnItemClickListener(new OnItemClickListener() { 
            public void onItemClick(AdapterView parent, View v, int position, long id) { 
                if (position >= imagesArray.length) { 
                    position = position % imagesArray.length; 
                } 
                Toast.makeText(CircularGallery.this, "" + position, Toast.LENGTH_SHORT).show(); 
            } 
        }); 
    
    }
    
    public class ImageAdapter extends BaseAdapter { 
        int mGalleryItemBackground; 
        private Context mContext; 
    
        public ImageAdapter(Context c) { 
            mContext = c; 
            TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); 
            mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0); 
    
            a.recycle(); 
        } 
    
        public int getCount() { 
            return Integer.MAX_VALUE; 
        } 
    
        public Object getItem(int position) { 
            if (position >= imagesArraylength) { 
                position = position % mImageIds.length; 
            } 
            return position; 
        } 
    
        public long getItemId(int position) { 
            if (position >= imagesArray.length) { 
                position = position % imagesArray.length; 
            } 
            return position; 
        } 
    
        public View getView(int position, View convertView, ViewGroup parent) { 
            ImageView i = new ImageView(mContext); 
            if (position >= imagesArray.length) { 
                position = position % imagesArray.length; 
            } 
            i.setImageResource(imagesArray[position]); 
            i.setLayoutParams(new Gallery.LayoutParams(80, 80)); 
            i.setScaleType(ImageView.ScaleType.FIT_XY); 
            i.setBackgroundResource(mGalleryItemBackground); 
            return i; 
        } 
    
        public int checkPosition(int position) { 
            if (position >= imagesArray.length) { 
                position = position % imagesArray.length; 
            } 
            return position; 
        } 
    }}
    

    Also, some developers have done such a functionality and you can find sources on their blogs

    • http://abhinavasblog.blogspot.com/2011/09/android-infinite-looping-gallery.html

    • http://blog.blundellapps.com/infinite-scrolling-gallery/

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.