View difference between Paste ID: aqxELXyU and xNasmnM1
SHOW: | | - or go back to the newest paste.
1
import android.R.integer;
2
import android.R.string;
3
import android.app.Activity;
4
import android.os.Bundle;
5
import android.view.View;
6
import android.widget.Button;
7
import android.widget.EditText;
8
import android.widget.TextView;
9
import android.widget.Toast;
10
11
public class MainActivity extends Activity {
12
13
 public EditText display;  
14
TextView edt;
15
Integer c,d,r,b;
16
String a="0",aa;
17
18
19
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16;
20
21
@Override
22
    public void onCreate(Bundle savedInstanceState) {
23
    super.onCreate(savedInstanceState);
24
    setContentView(R.layout.activity_main);
25
    edt=(EditText)findViewById(R.id.editText1);
26
    b1=(Button)findViewById(R.id.button1);
27
    b2=(Button)findViewById(R.id.button2);
28
    b3=(Button)findViewById(R.id.button3);
29
    b4=(Button)findViewById(R.id.button4);
30
    b5=(Button)findViewById(R.id.button5);
31
    b6=(Button)findViewById(R.id.button6);
32
    b7=(Button)findViewById(R.id.button7);
33
    b8=(Button)findViewById(R.id.button8);
34
    b9=(Button)findViewById(R.id.button9);
35
    b10=(Button)findViewById(R.id.button0);
36
    b11=(Button)findViewById(R.id.button11);
37
    b12=(Button)findViewById(R.id.button12);
38
    b13=(Button)findViewById(R.id.button13);
39
    b14=(Button)findViewById(R.id.button14);
40
    b15=(Button)findViewById(R.id.button15);
41
    b16=(Button)findViewById(R.id.button16);
42
43
44
45
    b1.setOnClickListener(new View.OnClickListener() {
46
         public void onClick(View v) {
47
             // TODO Auto-generated method stub
48
49
             a=edt.getText().toString();
50
             a=a+"1";
51
             edt.setText(a);
52
53
         }
54
     });
55
56
     b2.setOnClickListener(new View.OnClickListener()
57
     {
58
59
                 public void onClick(View v) {
60
                     // TODO Auto-generated method stub
61
62
                     a=edt.getText().toString();
63
                     a=a+"2";
64
                     edt.setText(a);
65
                                         }
66
             });
67
68
     b3.setOnClickListener(new View.OnClickListener()
69
     {
70
71
                 public void onClick(View v) {
72
                     a=edt.getText().toString();
73
                     a=a+"3";
74
                     edt.setText(a);
75
                                         }
76-
             });
76+
77
78
79
     b4.setOnClickListener(new View.OnClickListener()
80
     {
81
82
                 public void onClick(View v) {
83
                     a=edt.getText().toString();
84
                     a=a+"4";
85
                     edt.setText(a);
86
87
                                         }
88
             });
89
90
91
     b5.setOnClickListener(new View.OnClickListener()
92
     {
93
94
                 public void onClick(View v) {
95
96
                     a=edt.getText().toString();
97
                     a=a+"5";
98
                     edt.setText(a);
99
100
                 }
101
             });
102
103
104
     b6.setOnClickListener(new View.OnClickListener()
105
     {
106
107
                 public void onClick(View v) {
108
                     // TODO Auto-generated method stub
109
110
                     a=edt.getText().toString();
111
                     a=a+"6";
112
                     edt.setText(a);
113
                                         }
114
             });
115
116
117
     b7.setOnClickListener(new View.OnClickListener()
118
     {
119
120
                 public void onClick(View v) {
121
122
                     a=edt.getText().toString();
123
                     a=a+"7";
124
                     edt.setText(a);
125
                                         }
126
             });
127
128
129
     b8.setOnClickListener(new View.OnClickListener()
130
     {
131
132
                 public void onClick(View v) {
133
                     // TODO Auto-generated method stub
134
135
                     a=edt.getText().toString();
136
                     a=a+"8";
137
                     edt.setText(a);
138
139
                 }
140
             });
141
142
143
     b9.setOnClickListener(new View.OnClickListener()
144
     {
145
146
                 public void onClick(View v) {
147
                     // TODO Auto-generated method stub
148
149
                     a=edt.getText().toString();
150
                     a=a+"9";
151
                     edt.setText(a);
152
                                         }
153
             });
154
155
156
     b10.setOnClickListener(new View.OnClickListener()
157
     {
158
159
                 public void onClick(View v) {
160
                     // TODO Auto-generated method stub
161
162
                     a=edt.getText().toString();
163
                     a=a+"0";
164
                     edt.setText(a);
165
                 }
166
             });
167
168
169
 b11.setOnClickListener(new View.OnClickListener()
170
     {
171
172
                 public void onClick(View v) {
173
174
                       aa=a; 
175
                       b=1;    
176
                       a="";
177
                       edt.setText("+");
178
179
                     edt.setText("");
180
          }
181
             });
182
183
184
185
186
187
     b12.setOnClickListener(new View.OnClickListener()
188
     {
189
190
                 public void onClick(View v) {
191
192
                     aa=a;
193
                     b=2;
194
                     a="";
195
                     edt.setText("-");
196
                     edt.setText("");
197
198
                 }
199
             });
200
201
202
     b13.setOnClickListener(new View.OnClickListener()
203
     {
204
205
                 public void onClick(View v) {
206
                     aa=a;
207
                     b=3;
208
                     a="";
209
                     edt.setText("*");
210
                     edt.setText("");
211
212
                 }
213
             });
214
215
216
217
     b14.setOnClickListener(new View.OnClickListener()
218
     {
219
220
                 public void onClick(View v) {
221
                     aa=a;
222
                     b=4;
223
                     a="";
224
                     edt.setText("/");
225
                     edt.setText("");
226
227
                 }
228
             });
229
230
231
     b15.setOnClickListener(new View.OnClickListener()
232
     {
233
234
                 public void onClick(View v) {
235
236
                     if(b==1){
237
                       c=Integer.parseInt(aa);
238
239
                       d=Integer.parseInt(a);             
240
                       r=c+d;
241
                     }
242
                     else
243
                     if(b==4){
244
                         c=Integer.parseInt(aa);
245
                       d=Integer.parseInt(a);
246
                       r=c/d; 
247
                     }else
248
                         if(b==2){
249
                             c=Integer.parseInt(aa);
250
                           d=Integer.parseInt(a);
251
                           r=c-d; 
252
                         }
253
                         else
254
                             if(b==3){
255
                                 c=Integer.parseInt(aa);
256
                               d=Integer.parseInt(a);
257
                               r=c*d; 
258
                             }
259
                     Toast.makeText(MainActivity.this, "Result is::"+r, 10000).show();
260
                     c=0;
261
                     b=0;
262
                     d=0;
263
                     a="";
264
                     aa="";
265
                     edt.setText("");
266
                 }
267
             });
268
269
270
     b16.setOnClickListener(new View.OnClickListener()
271
     {
272
273
                 public void onClick(View v) {
274
                     // TODO Auto-generated method stub
275
276
                 edt.setText("");
277
                 }
278
             });
279
280
281
282
283
 }`