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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:20:02+00:00 2026-05-23T03:20:02+00:00

I have set an image for an ImageView using the setImageResource(R.drawable.icon1) . Now my

  • 0

I have set an image for an ImageView using the setImageResource(R.drawable.icon1).

Now my requirement is to find out what is the image that is set for an ImageView and do some processing.

Like

if (imageView.getImageResource() == R.drawable.icon1) {
  //do some processing
else if (imageView.getImageResource() == R.drawable.icon2) {
  //do somethign else
else 
 //display

So I would like to know if there exists a method(AFAIK, it doesn’t) and if it doesn’t how to keep a track of what resources have been set for an ImageView.

Thanks.
Sana.

  • 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-23T03:20:02+00:00Added an answer on May 23, 2026 at 3:20 am

    You’re assuming that because you put an integer in, you are able to get an integer back out, and that’s not how setImageResource() works. See ImageView#setImageResource(). This is just a convenience method for you: what Android is doing behind the scenes, is looking up the Drawable resource (in most cases, it’s a BitmapDrawable, but it could be any type), and then applying that resource to the ImageView as a Bitmap object (i.e., image data only — it does not have any idea what its original “resource id” was previously).

    Your best solution is going to be keeping track of the last resource id you used:

    imageView.setImageResource(R.drawable.image1);
    this.mLastResourceId = R.drawable.image1;
    // ...
    
    // Later, when checking the resource:
    if (this.mLastResourceId == R.drawable.image1) {
        // Do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ImageView with a source image set in the xml using the
I have set imageView's frame in table using the following code. cell.imageView.image = [UIImage
I have a GIF image that has an alpha set, and when my site
I have an image (PNG file) that has an alpha channel that is set
I have a listview which includes 2 textviews and 1 imageview. Now, the image
I have an imageview in which I want an image to be set. My
I have set a canvas' background to an image of a company logo. I
I have set of points which lies on the image. These set of points
I have created a Python file to generate a Mandelbrot set image. The original
I have a sprite image set as the background of an element on my

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.