일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- eslint-import-resolver-typescript
- react native #gradle
- 프레시업 #풀무원 #하루한병 #건강만들기 #풀무원 녹즙
- 네이버 클라우드 플랫폼
- visual studio code
- 티스토리 초대장/ 티스토리초대
- Path Alias
- code 세팅
- React Native
- 티스토리 초대장
- 초대장
- Emmet
- 티스토리초대
- GitHub Mirroring
- gitlab 연동
- webstorm
- GitLab Mirroring
- GitLab미러링
- GitHub 미러링
- 음료같은녹즙
- 니돈내먹
- settings sync
- code .
- visual studio code cli
- 실행시간 측정
- code 설치
- '티스토리 초대장/ 티스토리초대'
- currentTimeMillis
- 프리티어
- 유니옥션
Archives
- Today
- Total
방치하기
Android 계산기 tableLayout 본문
반응형
안드로이드 계산기 만들기
저걸 시켜서 과제로 만든건데 잘되는지는 모르겠다 ㅎ
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | package com.junho.cal; import android.R.color; import android.app.Activity; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; public class CalActivity extends Activity { /** Called when the activity is first created. */ int i; StringBuffer num1 = new StringBuffer(); StringBuffer num2 = new StringBuffer(); EditText result; int operationMode= 0 ; boolean isFirstNumber = true ; public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); //Edit Text result = (EditText)findViewById(R.id.EditText01); result.setBackgroundColor(Color.BLACK); result.setTextColor(Color.WHITE); result.setTextSize( 40 ); //버튼 Button[] digit = new Button[ 10 ]; digit[ 0 ] = (Button)findViewById(R.id.d0); Drawable alpha = digit[ 0 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 1 ] = (Button)findViewById(R.id.d1); alpha = digit[ 1 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 2 ] = (Button)findViewById(R.id.d2); alpha = digit[ 2 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 3 ] = (Button)findViewById(R.id.d3); alpha = digit[ 3 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 4 ] = (Button)findViewById(R.id.d4); alpha = digit[ 4 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 5 ] = (Button)findViewById(R.id.d5); alpha = digit[ 5 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 6 ] = (Button)findViewById(R.id.d6); alpha = digit[ 6 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 7 ] = (Button)findViewById(R.id.d7); alpha = digit[ 7 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 8 ] = (Button)findViewById(R.id.d8); alpha = digit[ 8 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 digit[ 9 ] = (Button)findViewById(R.id.d9); alpha = digit[ 9 ].getBackground(); alpha.setAlpha( 0 ); //알파값 0 for (i= 0 ; i < 10 ; i++) { digit[i].setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { if (isFirstNumber) { if (v.getId() == R.id.d0) { result.append(Integer.toString( 0 )); num1.append(Integer.toString( 0 )); } else if (v.getId() == R.id.d1) { result.append(Integer.toString( 1 )); num1.append(Integer.toString( 1 )); } else if (v.getId() == R.id.d2) { result.append(Integer.toString( 2 )); num1.append(Integer.toString( 2 )); } else if (v.getId() == R.id.d3) { result.append(Integer.toString( 3 )); num1.append(Integer.toString( 3 )); } else if (v.getId() == R.id.d4) { result.append(Integer.toString( 4 )); num1.append(Integer.toString( 4 )); } else if (v.getId() == R.id.d5) { result.append(Integer.toString( 5 )); num1.append(Integer.toString( 5 )); } else if (v.getId() == R.id.d6) { result.append(Integer.toString( 6 )); num1.append(Integer.toString( 6 )); } else if (v.getId() == R.id.d7) { result.append(Integer.toString( 7 )); num1.append(Integer.toString( 7 )); } else if (v.getId() == R.id.d8) { result.append(Integer.toString( 8 )); num1.append(Integer.toString( 8 )); } else if (v.getId() == R.id.d9) { result.append(Integer.toString( 9 )); num1.append(Integer.toString( 9 )); } } else { if (v.getId() == R.id.d0) { result.append(Integer.toString( 0 )); num2.append(Integer.toString( 0 )); } else if (v.getId() == R.id.d1) { result.append(Integer.toString( 1 )); num2.append(Integer.toString( 1 )); } else if (v.getId() == R.id.d2) { result.append(Integer.toString( 2 )); num2.append(Integer.toString( 2 )); } else if (v.getId() == R.id.d3) { result.append(Integer.toString( 3 )); num2.append(Integer.toString( 3 )); } else if (v.getId() == R.id.d4) { result.append(Integer.toString( 4 )); num2.append(Integer.toString( 4 )); } else if (v.getId() == R.id.d5) { result.append(Integer.toString( 5 )); num2.append(Integer.toString( 5 )); } else if (v.getId() == R.id.d6) { result.append(Integer.toString( 6 )); num2.append(Integer.toString( 6 )); } else if (v.getId() == R.id.d7) { result.append(Integer.toString( 7 )); num2.append(Integer.toString( 7 )); } else if (v.getId() == R.id.d8) { result.append(Integer.toString( 8 )); num2.append(Integer.toString( 8 )); } else if (v.getId() == R.id.d9) { result.append(Integer.toString( 9 )); num2.append(Integer.toString( 9 )); } } } }); } Button clearBtn=(Button)findViewById(R.id.clear); clearBtn.setOnClickListener( new Button.OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.clear) { result.setText( null ); num1 = new StringBuffer(); num2 = new StringBuffer(); isFirstNumber = true ; } } }); Button plusBtn=(Button)findViewById(R.id.plus); plusBtn.setOnClickListener( new Button.OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.plus) { if (isFirstNumber) { isFirstNumber = false ; operationMode = 1 ; result.setText( null ); } } } }); Button minusBtn=(Button)findViewById(R.id.minus); minusBtn.setOnClickListener( new Button.OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.minus) { if (isFirstNumber) { result.setText( null ); isFirstNumber = false ; operationMode = 2 ; } } } }); Button multiBtn=(Button)findViewById(R.id.multi); multiBtn.setOnClickListener( new Button.OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.multi) { if (isFirstNumber) { result.setText( null ); isFirstNumber = false ; operationMode = 3 ; } } } }); Button divBtn=(Button)findViewById(R.id.div); divBtn.setOnClickListener( new Button.OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.div) { if (isFirstNumber) { result.setText( null ); isFirstNumber = false ; operationMode = 4 ; } } } }); Button equalBtn=(Button)findViewById(R.id.equal); equalBtn.setOnClickListener( new Button.OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.equal) { String tempNum1=num1.toString(); String tempNum2=num2.toString(); float tempResult; switch (operationMode) { case 0 : break ; case 1 : tempResult=Float.parseFloat(tempNum1)+Float.parseFloat(tempNum2); result.setText(Float.toString(tempResult)); num1= new StringBuffer(); num2= new StringBuffer(); num1.append(Float.toString(tempResult)); operationMode= 0 ; isFirstNumber= true ; break ; case 2 : tempResult=Float.parseFloat(tempNum1)-Float.parseFloat(tempNum2); result.setText(Float.toString(tempResult)); num1= new StringBuffer(); num2= new StringBuffer(); num1.append(Float.toString(tempResult)); operationMode= 0 ; isFirstNumber= true ; break ; case 3 : tempResult=Float.parseFloat(tempNum1)*Float.parseFloat(tempNum2); result.setText(Float.toString(tempResult)); num1= new StringBuffer(); num2= new StringBuffer(); num1.append(Float.toString(tempResult)); operationMode= 0 ; isFirstNumber= true ; break ; case 4 : tempResult=Float.parseFloat(tempNum1)/Float.parseFloat(tempNum2); result.setText(Float.toString(tempResult)); num1= new StringBuffer(); num2= new StringBuffer(); num1.append(Float.toString(tempResult)); operationMode= 0 ; isFirstNumber= true ; break ; } } else { } } }); Drawable alpha1 = clearBtn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 alpha1 = plusBtn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 alpha1 = minusBtn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 alpha1 = divBtn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 alpha1 = multiBtn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 alpha1 = equalBtn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 Button s1Btn=(Button)findViewById(R.id.s1); Button s2Btn=(Button)findViewById(R.id.s2); Button s3Btn=(Button)findViewById(R.id.s3); Button dotBtn=(Button)findViewById(R.id.s4); dotBtn.setOnClickListener( new Button.OnClickListener() { @Override public void onClick(View v) { if (v.getId() == R.id.s4) { if (isFirstNumber) { result.append( "." ); num1.append( "." ); } else { result.append( "." ); num2.append( "." ); } } } }); alpha1 = s1Btn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 alpha1 = s2Btn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 alpha1 = s3Btn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 alpha1 = dotBtn.getBackground(); alpha1.setAlpha( 0 ); //알파값 0 } } |
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 | <!--?xml version="1.0" encoding="utf-8"?--> < tablelayout android:stretchcolumns = "*" android:layout_marginbottom = "0px" android:layout_margintop = "0px" android:background = "@drawable/cal" android:layout_height = "fill_parent" android:layout_width = "320px" xmlns:android = "http://schemas.android.com/apk/res/android" > < edittext android:layout_height = "60px" android:layout_width = "310px" android:gravity = "right" android:id = "@+id/EditText01" android:text = "" ></ edittext > < tablerow android:layout_height = "20px" android:layout_width = "320px" android:gravity = "left" > < button android:layout_height = "25px" android:layout_width = "85px" android:id = "@+id/s1" android:text = "" ></ button > < button android:layout_height = "25px" android:layout_width = "85px" android:id = "@+id/s2" android:text = "" ></ button > < button android:layout_height = "25px" android:layout_width = "85px" android:id = "@+id/s3" android:text = " " ></ button > < button android:layout_height = "25px" android:layout_width = "85px" android:id = "@+id/clear" android:text = "" ></ button > </ tablerow > < tablerow android:layout_marginbottom = "0px" android:layout_margintop = "0px" android:layout_width = "fill_parent" android:padding = "0px" > < button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d7" android:text = "" android:padding = "0px" android:fadingedge = "none" ></ button > < button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d9" android:text = "" android:padding = "0px" ></ button > < button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d8" android:text = "" android:padding = "0px" ></ button > < button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/div" android:text = "" android:padding = "0px" > < tablerow android:layout_width = "fill_parent" > </ tablerow ></ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d4" android:text = "" > </ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d5" android:text = "" > </ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d6" android:text = "" > </ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/multi" android:text = "" > < tablerow android:layout_width = "fill_parent" > </ tablerow ></ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d1" android:text = "" > </ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d2" android:text = "" > </ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d3" android:text = "" > </ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/minus" android:text = "" > < tablerow android:layout_width = "fill_parent" > </ tablerow ></ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/s4" android:text = "" ></ button > < button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/d0" android:text = "" > </ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/equal" android:text = "" > </ button >< button android:layout_height = "90px" android:layout_width = "85px" android:id = "@+id/plus" android:text = "" > < pre ></ pre ></ button ></ tablerow ></ tablelayout > |
반응형