0% found this document useful (0 votes)
10 views1 page

Activity2 Calculator

The document outlines the steps to create a basic Android calculator project in Android Studio. It includes instructions for setting up the layout with two number input fields, buttons, and a TextView, as well as providing a Java method to handle addition. The method retrieves input values, performs the addition, and displays the result in the TextView.

Uploaded by

Melo Catindoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Activity2 Calculator

The document outlines the steps to create a basic Android calculator project in Android Studio. It includes instructions for setting up the layout with two number input fields, buttons, and a TextView, as well as providing a Java method to handle addition. The method retrieves input values, performs the addition, and displays the result in the TextView.

Uploaded by

Melo Catindoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ACTIVITY 2: ANDROID CALCULATOR

1. Create project in Android Studio, name the project calculator.


2. In layout folder, select activity_main.xml
3. Select Design tab.
4. In Palette tool, select Text and place 2 Number /s object.
5. Add buttons and TextView.
6. In activity_main.xml, add this statement in Button:

android:onClick="btnadd"

7. In Java Main Activity, copy and paste the code below.

public void btnadd(View view) {


final EditText eNum1=(EditText)findViewById(R.id.txtNum1) ;
final EditText eNum2=(EditText)findViewById(R.id.txtNum2) ;
final TextView lblRes=(TextView) findViewById(R.id.txtRes) ;
int intVal1 = Integer.parseInt(eNum1.getText().toString());
int intVal2 = Integer.parseInt(eNum2.getText().toString());
lblRes.setText(String.valueOf(intVal1 + intVal2));

You might also like