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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:42:58+00:00 2026-05-21T19:42:58+00:00

sorry to ask question already asked. but i am helpless in my programi have

  • 0
     sorry to ask question already asked. but i am helpless
   in my programi have 27 imageview's  which can display any of the 3 drawable's  i have in my drawable's folder.. and i want these imageview's  click to perform a different action for each drawable they contain..but i found that we won't be able to compare two drawable's for equality....

here’s the code i wrote, which didn’t work….

if(((ImageView)arg0).getDrawable() != getResources().getDrawable(R.drawable.sq))

i have googled it but no one was clear….they were saying we could use setTag() method but i am not able to figure out How . so please have pity on me and tell me how could i use setTag() in solving my problem with a example

  • 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-21T19:42:59+00:00Added an answer on May 21, 2026 at 7:42 pm

    Using setTag() is pretty straightforward. Either you use void setTag (Object tag) and you just provide an object to identify your drawable (typically a String) or if you need to store several properties you can use the void setTag (int key, Object tag) to provide an integer key.

    Code example (this code has not been tested but it should explain what I mean by itself):

    class MyActivity extends Activity {
    
    private static final String FIRST_IMAGE = "firstImage";
    private static final String SECOND_IMAGE = "secondImage";
    
    protected void onCreate (Bundle savedInstanceState) {
    // Instantiation
    ImageView imageView = (ImageView) findViewById(R.id.imgview);
    imageView.setImageResource(R.drawable.firstimage);
    imageView.setTag(FIRST_IMAGE); // The view is now tagged, we know this view embeds the first image
    imageView.setOnClickListener(new ImageClickListener());
    
    ImageView anotherImageView = (ImageView) findViewById(R.id.secondimgview);
    anotherImageView.setImageResource(R.drawable.firstimage);
    anotherImageView.setTag(FIRST_IMAGE); // The view is now tagged, we know this view embeds the first image
    anotherImageView.setOnClickListener(new ImageClickListener());
    
    ImageView secondImageView = (ImageView) findViewById(R.id.thirdimgview);
    secondImageView.setImageResource(R.drawable.secondimage);
    secondImageView.setTag(SECOND_IMAGE); // The view is now tagged, we know this view embeds the second image
    secondImageView.setOnClickListener(new ImageClickListener());
    }
    
    private class ImageClickListener implements View.OnClickListener {
    
    // The onClick method compares the view tag to the different possibilities and execute the corresponding action.
        public void onClick(View v) {
            String tag = (String) v.getTag();
            if (v.getTag() == FIRST_IMAGE) {
                // perform specific action
            } else if (v.getTag() == SECOND_IMAGE) {
    
            }
        }
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sorry to ask this question when it has already been asked but
I'm sorry if I ask a question that's been asked before, but I could
Sorry to ask a question like that but I can't found a good answer
Sorry, this's my first time to ask a question here. So, I don't have
(I am sorry, I wanted to ask this question on meta first, but it
Sorry for being the 100000th person to ask the same question. But I guess
Sorry if I will ask the question that already exists or just has easy
I am using cakePHP 1.26. I am sorry to ask this question, but I
I am sorry to ask this trivial question but I could not find a
I'm sorry to ask such a simple question, but it's a specific question I've

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.