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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:12:33+00:00 2026-05-16T04:12:33+00:00

I have a very simple question about menu control in Android. I’m writing a

  • 0

I have a very simple question about menu control in Android. I’m writing a program that performs some simple numeric calculations and outputs an answer. My question is how do make the program move to second screen when a button is pressed, and how can I let the user move back to the original screen.
Here’s a quick example

Screen 1

"Add Numbers"

Input 1st # ____       
Input 2nd # ____      
(Add) 

Screen 2

The answer is "____"

The user inputs two integers. presses add, and then the program moves to the second screen which displays the answer. If they user wants they can return to the first screen and start over.

I know this has been covered but with so many resources I don’t know what to look for. Answers or links to resources would be most helpful. Thank you!

  • 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-16T04:12:33+00:00Added an answer on May 16, 2026 at 4:12 am

    You can use the following layout for the screen to input numbers. Name the file first.xml.

      <TextView
            android:id="@+id/firstnumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Input Ist:"
            android:textSize="20px"
            android:textStyle="bold"
            />
    
     <EditText 
             android:id="@+id/first"
             android:layout_height="wrap_content"
             android:layout_width="250px"
    
       /> 
    
        <TextView 
             android:id="@+id/secondnumber"
             android:text = "Input 2nd"  
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textSize="20px"
             android:textStyle="bold"
             />     
    
        <EditText 
                  android:id="@+id/second"
                      android:layout_height="wrap_content"
                      android:layout_width="250px"
    
          /> 
    
         <Button 
              android:id="@+id/add_button"
                  android:text="Add"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:textSize="15px"
                  android:layout_centerHorizontal="true"
    
                  /> 
    
    </LinearLayout>
    

    To add these numbers

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.first);
             Button add = (Button) findViewById(R.id.add);
            add.setOnClickListener(this);
            EditText num1 = (EditText)findViewById(R.id.first);
            EditText num2 = (EditText)findViewById(R.id.second);
    }
    

    The click listener code

    public void onClick(View v) {
    
                    int n1 = Integer.parseInt(num1.getText().toString());
                    int n2 = Integer.parseInt(num2.getText().toString());
                    int result = n1 + n2;
                    String res = Integer.toString(result);
                                    Intent intent = new Intent(getApplicationContext(), Result.class);
                                    intent.putExtra("result", result); //Passing the result to the second activity using intent
                    startActivity(intent);
                    }
    

    In the Result.java class.

    public class Result extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.result);
                Intent intent = getIntent();
                    String result = intent.getStringExtra("result");
                    TextView t1 = (TextView)findViewById(R.id.result);
                    t1.setText(result);
        }
    }
    

    Hope this helps..

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

Sidebar

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.