tags:

views:

21

answers:

1

Just learning and thought this would be neat to learn.

basically getting the value from editText1 and editText2, then by pressing an add button, be able to show the result answer on a second activity. I know this is probably very easy, but I wanted to learn more about how I can do simple math practice while learning the language. Thank you for your time if you respond.

A: 
  1. To get the value from an EditText view, call editText.getText() and save it to a (String) variable.

  2. Parse the String as an Integer using Integer.parseInt(str). Add your two integers together in the normal manner (var1 + var2).

  3. To start a new Activity, create an Intent that refers to the Activity class you want (Intent intent = new Intent(context, MyActivity.class).

  4. Add your sum as an extra to the intent to share it with the new activity (intent.putExtra("sum", sumVar)).

  5. Start the activity with startActivity(intent).

  6. In the onCreate() method of your new activity, you can call getIntent() to retrieve the Intent that was used to start it. Then you can call intent.getIntExtra("sum") to retrieve your sum.

  7. You can display it in a TextView with textview.setText(String.valueOf(sum))

antonyt
Thank you very much for helping me!
Steve