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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:11:56+00:00 2026-05-27T15:11:56+00:00

Sorry in advance in case this is a stupid question! I was playing around

  • 0

Sorry in advance in case this is a stupid question!

I was playing around with a couple of things in Android, and I was experimenting with changing elements at run time which were specified in the xml file.

Button buttonSetup = (Button) findViewById(R.id.buttonSetup);
buttonSetup.setTextSize(40);

However, I noticed that this crashed the application if you make the changes before –

setContentView(R.layout.main);

What is the reason for this? (Sorry if I’m missing something obvious! I think my brain has gone into hibernation for Winter!)

I had thought it would be best practice to alter elements before setContentView, so that if you alter a lot of elements (say half a dozen or so attributes over half a dozen elements) it is not obvious to the user with things changing on screen.

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-27T15:11:57+00:00Added an answer on May 27, 2026 at 3:11 pm

    Easy answer:

    Your xml-Layout is inflated by calling setContentView.
    Before you haven’t inflated it, the Activity doesn’t know about the XML.

    You can manually inflate a View with this code:

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout myLayout = (LinearLayout) inflater.inflate(R.layout.nameOfXML, null);
    

    and later set the View to this inflated layout with

    setContentView(myLayout);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry in advance for this being such a beginner question. Here are the steps
Sorry in advance everyone for this question as I know the cascading select boxes
Sorry in advance as this question is similar (but not the same!) to others.
This is a very elemental question about object-orientated programming- so sorry in advance if
I'm sorry in advance if this question is really weird. I am sending data
In advance: sorry for the noob question but I'm learning Cocoa & Objective-C and
I am new to JPA and JBoss, so sorry in advance if this is
Sorry if this is too simple, but thanks in advance for helping. This is
Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get

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.