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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:43:44+00:00 2026-05-22T19:43:44+00:00

I have an xml file right now which has a TableLayout within a LinearLayout.

  • 0

I have an xml file right now which has a TableLayout within a LinearLayout. Within the TableLayout are TableRows with Buttons. Within my Java code, I do a setOnClickListener for each button.

The problem is I have several xml files like this which are exactly the same, except within the xml the ID and text’s of the different buttons are different.

So one file it will be

<Button android:id="@+id/one" android:text="one" /> 
<Button android:id="@+id/two" android:text="two" /> 

and another file it will be

<Button android:id="@+id/three" android:text="three" />
<Button android:id="@+id/four" android:text="four" />

In Java, in one part of a switch/case statement I have a case that is:

setContentView(R.layout.a);
Button bOne = (Button) findViewById(R.id.one);
Button bTwo = (Button) findViewById(R.id.two);

and another I have:

setContentView(R.layout.b);
Button bThree = (Button) findViewById(R.id.three);
Button bFour = (Button) findViewById(R.id.four);

The redundancy goes out to more than two xml files, this is just an example.

Is there any way to do this and not have multiple layout files, but to do this all in one layout file? The xml files are all exactly the same, but for the id and text portions of the buttons.

I really don’t care how this is done – in Java, in xml, or however. It’s just that I make minor tweaks to the layout once in a while, and don’t want to have to continue to tweaking every file with exactly the same layout but for the button id’s and texts. I’d like to tweak the layout once and have it work across all of them when I change the layout. If I have to put the entire layout file in Java, that would be fine.

  • 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-22T19:43:45+00:00Added an answer on May 22, 2026 at 7:43 pm

    just keep one xml file (a.xml). say the ids of the two buttons be id1 and id2. use setContentView(R.layout.a);. Next declare 2 buttons say b1 and b2. set b1 = (Button) findViewById(R.id.id1) and b2 = (Button) findViewById(R.id.id2). put setOnClickListener for the buttons in the switch-case

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

Sidebar

Related Questions

I have a java servelet segment, which can generate a XML file and print
So I have this code right, and it basically reads an XML file and
I have an XML file, which I open in F# like this: let Bookmarks(xmlFile:string)
I have an xml file from which I am extracting html using LINQ to
I have a small C# program to modify a xml file which is located
I have a simple XML file here which I converted to XSD with xsd.exe
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an xml file providing data for a datagrid in Flex 2 that
I have an xml file where I need to comment out a whole piece
I have an XML file loaded into a DOM document, I wish to iterate

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.