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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:29:27+00:00 2026-06-03T06:29:27+00:00

I know that the base different is that setId() takes int as a parameter,

  • 0

I know that the base different is that setId() takes int as a parameter, while setTag() takes Object. I am asking more about practical advice.

When I generate more same elements programmatically, I set their IDs via setId(++counter) and that is fine for me to know which element has sent the onClick event. And I could do the same thing via setTag(++counter), but I am used to the previous approach.

So when should I use setTag() and am I making a mistake when using setId()?

I guess if my way is right, then I’d use setTag() when I want to pass additional data, but I’ll leave you comment on this issue first.

  • 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-03T06:29:28+00:00Added an answer on June 3, 2026 at 6:29 am

    Your guess is right. You should use the setId() when you only want a way to identify that particular View in your code and setTag when you want to pass additional information along with that View(that additional data may or may not uniquely identify that View).
    You could use only the setTag method and pass a compound object that contains id + additional data but in this situation you are required to build a special object instead of the more simply way, calling the two methods in question.

    Edit :
    The docs for the View class also contain valuable information about those two methods:

    IDs

    Views may have an integer id associated with them. These ids are
    typically assigned in the layout XML files, and are used to find
    specific views within the view tree.

    Tags

    Unlike IDs, tags are not used to identify views. Tags are essentially
    an extra piece of information that can be associated with a view. They
    are most often used as a convenience to store data related to views in
    the views themselves rather than by putting them in a separate
    structure.

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

Sidebar

Related Questions

I know that an MVC framework allows you to separate business logic, data base
Yes, I know that downcast using dynamic_cast can't compile if the Base is not
I know that exceptions have a performance penalty, and that it's generally more efficient
My situation is that I screwed up essentially. I inherited my code base about
I was reading about Empty Base Optimization(EBO). While reading, the following questions popped up
I know that it's a subject that can raise a lot of debate, but
I know that one of the differences between classes and structs is that struct
We know that behind the scenes, the ASP.NET MVC framework will use reflection to
I know that I should put all the html elements in body tag, but
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public

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.