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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:09:48+00:00 2026-06-15T10:09:48+00:00

So for this I am trying to take 2 integer values the user inputs

  • 0

So for this I am trying to take 2 integer values the user inputs in the 2 EditTexts provided in the main activity and add them together. Then, I want the android application to switch to the 2nd Activity and in the EditText box there display the sum of the 2 values entered into the 2 EditText boxes from the previous(main) Activity.

I think I’m on the right track, but I’m not quite certain how to obtain the sum in the second activity. I’ve tried messing with bundles and such, but I still can’t quite figure it out.

**Re-edited to reflect some suggestions. The 2nd activity still does not show the total…I’m thinking it’s a conversion error of some sort.

***I’m almost positive it has something to do with the 2nd Activity..the first looks right to me

**PERFECT! It was a conversion error. Thanks all for the help 😀

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;


public class MainActivity extends Activity 
{   

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void OnClick(View v) //android:onClick="OnClick"   added to activity_main.xml for this button
    {
        Intent intent = new Intent(MainActivity.this, Summation.class);
    EditText v1 = (EditText)findViewById(R.id.editText1);
    EditText v2 = (EditText)findViewById(R.id.editText2);   
    int first =  Integer.parseInt(v1.getText().toString());
    int second = Integer.parseInt(v2.getText().toString());
    String sum = String.valueOf(first + second);
    intent.putExtra("sum", sum);
    startActivity(intent);          
    }
}

Second Activity Class

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;

public class Summation extends Activity 
{
    //Second Activity 

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_2);        
        String sum = (getIntent().getExtras().getString("sum"));
        EditText addsum = (EditText)findViewById(R.id.editText1);
        addsum.setText(sum);

    }   
}
  • 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-15T10:09:49+00:00Added an answer on June 15, 2026 at 10:09 am

    You can’t assign your int value straight from edittext. You need to assign the edit texts like

    EditText eText1 = (EditText) findViewById(R.id.yourfirstedittext)
    

    and the same with your second. Then get the values

    int firstNum = Integer.parseInt(eText1.getValue.toString())

    and of course the same with the second. You can then add these two ints together and simply pass them with intent.putExtra("sume, sum). Then get them in your second Activity with getIntent()

    Intent ci = getIntent();
    final int sum = ci.getIntExtra("sum", yourDefaultIntValue)
    

    If you are passing as an int you will need to do it this way and get the String value of the int. But if you pass as a String then you are fine

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

Sidebar

Related Questions

I am trying to take in array which contains some integer values/string values from
trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
I'm trying to take this string where lowercase(pdd.last_name) like 'albert%' and replace pdd with
Really struggling to figure this out. Just trying to take in data from php
Ok, I'm very simply trying to take this example... http://jsfiddle.net/shanabus/HGF59/ and put it on
Hi please take a look at this fiddle http://jsfiddle.net/bloodygeese/pwjNQ/1/ I am trying to figure
could anyone take a look at this for me? Problem: trying to output a
I am trying to make a simple alarm. in this code portion a take
I'm trying to take an ADO Recordset and then loop through it to parse
What I'm trying to do is take this code: char naive_smooth_descr[] = naive_smooth: Naive

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.