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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:40:54+00:00 2026-06-10T12:40:54+00:00

I’m an amateur developer creating a short app and I’m having trouble using both

  • 0

I’m an amateur developer creating a short app and I’m having trouble using both the XML file for a particular activity along with Activity’s Java method “setContentView”. I need the method because I am generating numbers from a computation and the number generated is variable depending on different parameters. Therefore, each time I call the computation I have to call:

textView.setText(message + " is " + output);
setContentView(textView);

But I also created several buttons on the Activity’s XML page which I would also like to show up on the Activity’s page. For example, this is one of the buttons I created:

<Button 
    android:layout_marginTop="100dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_quit"
    android:onClick=".quit" />

However, if I call:

setContentView(R.layout.activity_compute_number);

after the set content view for the variable text message I mentioned earlier, the XML file overrides the text message and the text message never shows up and vice versa if I call the two setContentView methods the other way around. How do I get them both to render on the Activity screen simultaneously?

  • 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-10T12:40:55+00:00Added an answer on June 10, 2026 at 12:40 pm

    In your activity_compute_number.xml, you should assign an id to your button and textview. This way you can reference your button and textView.

     <Button
        android:id="@+id/button_compute"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:onClick=".quit"
        android:text="@string/button_quit" />
    
    <TextView
        android:id="@+id/textView_answer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp" />
    

    Notice the android:id=”@+id/button_compute” and android:id=”@+id/textView_answer”. This gives this button and textview id’s called button_compute and textView_answer respectively.

    Then change your onCreate to the following:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        Button btnCompute = (Button)findViewById(R.id.button_compute);
        TextView tvAnswer = (TextView)findViewById(R.id.textView_answer);
    
    
        btnCompute.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
    
                /*
                 * DO COMPUTATION here
                */
    
                tvAnswer.setText(answer);
            }
        });
    }
    

    In onCreate() method you set your view to show the layout in your activity_compute_number.xml by calling setContentView() only once. You reference your button and textview by findViewById specifying the id’s you have set in your xml.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
In my XML file chapters tag has more chapter tag.i need to display chapters
I am writing an app with both english and french support. The app requests
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm parsing an XML file, the creators of it stuck in a bunch social
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.