An open API service indexing awesome lists of open source software.

https://github.com/sayed3li97/simplecalculator-android

This project is part of Introduction to Android workshop. The exercise is a Simple Calculator app that "Plus", "Minus" and "Multiplication" two numbers. This exercise aims to introduce Java data types, casting and operations within the Android environment
https://github.com/sayed3li97/simplecalculator-android

Last synced: about 1 year ago
JSON representation

This project is part of Introduction to Android workshop. The exercise is a Simple Calculator app that "Plus", "Minus" and "Multiplication" two numbers. This exercise aims to introduce Java data types, casting and operations within the Android environment

Awesome Lists containing this project

README

          

# SimpleCalculator

This project is part of the Introduction to Android workshop. The exercise is a Simple Calculator app with "Plus," "Minus," and "Multiplication" two numbers. This exercise introduces Java data types, casting, and operations within the Android environment.

# Steps to re-create
1. Create a new project in Android Studio (Choose the Empty Activity)
2. Navigate to app/res/layout/activity_main.xml
3. Open the Text view, and the replace the XML code with the below code
```


```
4. Open the java file for the main activity by opening the MainActivity.java from the following path app/java/"The first folder"/MainActivity.java
5. Replace the code in that file with the below code ("Don't remove the first line starting with the package")
```

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

//Declare these Variable in this location to be accessed by all the functions in this class
private EditText Input1;
private EditText Input2;
private TextView Results;

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

Input1 = (EditText) findViewById(R.id.inputText1);
Input2 = (EditText) findViewById(R.id.inputText2);
Results = (TextView) findViewById(R.id.results);

}

public void plus(View view){
int input1 = Integer.parseInt(Input1.getText().toString());
int input2 = Integer.parseInt(Input2.getText().toString());
String res = String.valueOf(input1 + input2);
Results.setText(res);
}

public void minus(View view){
int input1 = Integer.parseInt(Input1.getText().toString());
int input2 = Integer.parseInt(Input2.getText().toString());
String res = String.valueOf(input1 - input2);
Results.setText(res);
}

public void multi(View view){
int input1 = Integer.parseInt(Input1.getText().toString());
int input2 = Integer.parseInt(Input2.getText().toString());
String res = String.valueOf(input1 * input2);
Results.setText(res);
}
}

```

Thank you!