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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:19:30+00:00 2026-05-18T00:19:30+00:00

Currently I am careful to use different IDs for each widget, but if I

  • 0

Currently I am careful to use different IDs for each widget, but if I used the same id for some widgets in different layout xml files, what would happen to my calls to findViewById? Would it get confused and return a widget from the wrong layout file?

I ask because I was thinking of including a view (with a row of buttons) in some other views, then each of those screen classes would have to assign a slightly different behavior to each button on the included view. But to do that they would be calling findViewById on the same id.
For instance currently I do like this in each file:

final ImageButton homeButton = (ImageButton)this.findViewById(R.id.rshome_button);
homeButton.setOnClickListener(new BottomButtonClickListener());

final ImageButton hotButton = (ImageButton)this.findViewById(R.id.rshotlist_button);
hotButton.setOnClickListener(new BottomButtonClickListener());

final ImageButton locButton = (ImageButton)this.findViewById(R.id.rsbot_map);
locButton.setOnClickListener(new BottomButtonClickListener());

final ImageButton sendButton = (ImageButton)this.findViewById(R.id.rssend_button);
sendButton.setOnClickListener(new BottomButtonClickListener());

But I change the R.id in each file to point to the widget in each assiciated layout. it would be nice if I could use the one R.id for all so I don’t have to tweak every layout file and every screen class.

Thanks

  • 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-18T00:19:30+00:00Added an answer on May 18, 2026 at 12:19 am

    It should be fine as long as you don’t instantiate both layouts in the same activity. But having never tried it I wouldn’t like to guarantee it.

    However, I wouldn’t be surprised if the Android code generator errors out though, as it will probably try to create two R.id.rshome_button entries in your R.java file.

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

Sidebar

Related Questions

I haven't used OLE/COM for quite some time as a developer, but I currently
Currently I am using HTML files for parts of my user interface. I display
Currently I am trying to use a bunch of custom perl modules, test.pm as
I have some experience with ANTLR 2's C++ target, but have been hesitant to
Currently I use 1.4.4 in my sites, and considering upgrading to the latest (1.6.4).
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently I'm starting a new Activity and calling finish on a current one. Is
Currently, I'm working on a project where I have a server - client relationship
Currently I have 2 ways of displaying images in a cell, which way will

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.