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 3760926
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:32:49+00:00 2026-05-19T10:32:49+00:00

I apologize if this seems really simple but I can’t figure it out. I

  • 0

I apologize if this seems really simple but I can’t figure it out. I have an ImageButton that I want to change the image of at run-time based on a button click. I have 5 images in my res folder. When the user hits the “Next” button, I want it to go to the next image. The file names of the images are image1.png, image2.png, etc.

I know I you can change the image by doing:

imgButton.setImageResource(R.drawable.image2);

I have a counter (int) to keep track of the image number being displayed. But how would i change the image to the next image? Any help would be appreciated.

  • 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-05-19T10:32:49+00:00Added an answer on May 19, 2026 at 10:32 am

    Create an Array of integers to hold the references to your images, e.g.

    int[] images = new int[5];
    images[0] = R.drawable.image001;
    images[1] = R.drawable.image002;
    images[2] = R.drawable.image003;
    images[3] = R.drawable.image004;
    images[4] = R.drawable.image005;
    

    And then increment your counter on each click, and set the image resource using a value from your array:

    imgButton.setImageResource(images[counter]);
    

    Easy when you know how… 😉

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

Sidebar

Related Questions

I apologize for this seemingly relatively simple task that I can't figure out. I
I apologize if this is a noob question, but I can't seem to figure
Sorry if this question may be simple, but I can't seem to find an
Apologies if this is something really simple. I've found various C# examples here, but
This probably sounds really stupid but I have noo idea how to implement jquery's
Ok, maybe I'm missing something really simple and I apologize if that's the case,
I apologize because this seems like such a simple thing. What's the correct way
Firstly apologies if this is a really simple question but Git is absolutely brand
I'm new to PHP so I apologize if this seems silly. I've searched around
I apologize in advance if this question seems confused. The behaviour I am seeing

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.