-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
77 lines (58 loc) · 2.28 KB
/
MainActivity.java
File metadata and controls
77 lines (58 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package abhisheklomsh.calculator;
import android.content.Intent;
import android.support.annotation.IntegerRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button btnrel;
EditText txtval1,txtval2;
TextView mTextView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnrel=(Button)findViewById(R.id.btnsum);
Button btnmul=(Button)findViewById(R.id.button);
Button btndiv=(Button)findViewById(R.id.button2);
Button btnsub=(Button)findViewById(R.id.button3);
txtval1=(EditText)findViewById(R.id.txtval1);
txtval2=(EditText)findViewById(R.id.txtval2);
mTextView = (TextView) findViewById((R.id.textView3));
btnrel.setOnClickListener(this);
btnmul.setOnClickListener(this);
btndiv.setOnClickListener(this);
btnsub.setOnClickListener(this);
}
public void onClick(View v) {
int value1=Integer.parseInt(txtval1.getText().toString());
int value2=Integer.parseInt(txtval2.getText().toString());
int rel=value1+value2;
int mul = value1*value2;
float div = (float)value1/value2;
int sub = value1-value2;
switch (v.getId()) {
case R.id.btnsum:
Toast.makeText(this, String.valueOf(rel), Toast.LENGTH_SHORT).show();
mTextView.setText(rel);
break;
case R.id.button:
Toast.makeText(this, String.valueOf(mul), Toast.LENGTH_SHORT).show();
mTextView.setText(mul);
break;
case R.id.button2:
Toast.makeText(this, String.valueOf(div), Toast.LENGTH_SHORT).show();
break;
case R.id.button3:
Toast.makeText(this, String.valueOf(sub), Toast.LENGTH_SHORT).show();
mTextView.setText(sub);
break;
default:
break;
}
}
}