1 / 15

To be an Android Expert

앱창작터. To be an Android Expert. 안드로이드 여대생 기초 과정. Simple Calculator - Final Implementation. 문양세 , 최미정 강원대학교 IT 대학 컴퓨터학부. 최종계산기를 완성해 봅시다 ~. OnClickListener 버튼 등록 - 설명. 추가된 4 개 버튼에 대해 이벤트를 할당한다 . 각 버튼의 객체는 findViewById () 를 통해 얻어오고 , 이벤트 리스너 mClickListener () 을 등록한다 .

ila-riley
Télécharger la présentation

To be an Android Expert

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 앱창작터 To be an Android Expert • 안드로이드여대생 기초 과정 Simple Calculator - Final Implementation 문양세, 최미정 강원대학교 IT대학 컴퓨터학부

  2. 최종계산기를 완성해 봅시다~

  3. OnClickListener버튼 등록 - 설명 • 추가된 4개 버튼에 대해 이벤트를 할당한다. • 각 버튼의 객체는 findViewById()를 통해 얻어오고,이벤트 리스너mClickListener()을등록한다. • 추가된 4개의 버튼은 다음과 같다. • R.id.btn_sign: 부호(+/-) 버튼 • R.id.btn_sqrt: 제곱근(루트) 버튼 • R.id.btn_percent: 백분율(퍼센트) 연산(%) 버튼 • R.id.btn_bosu: 역수(1/x) 버튼

  4. OnClickListener버튼 등록 – 코드

  5. OnClickListener추가 – 설명 • 루트 버튼(R.id.btn_sqrt)이면, specialPress(‘s’)를,퍼센트 버튼(R.id.btn_percent)이면, specialPress(‘%’)를, 역수 버튼(R.id.btn_bosu)이면, specialPress(‘x’)를각각 호출한다. 부호 버튼(R.id.btn_sign)이 눌렸을 때, signPress() 메소드를 호출한다.

  6. OnClickListener추가 - 코드

  7. signPress()– 설명 • 현재 첫 번째 문자가 ‘-’이면, 이 첫 번째 문자를 제거하여 양수로 만든다. • 현재 첫 번째 문자가 ‘-’가아니면, 첫 번째 문자로 ‘-’를 추가하여 음수로 만든다. 현재 TextView의 값을 가져와 양쪽 여백을 제거한다.

  8. signPress() - 코드

  9. specialPress()– 설명 (1/3) • 현재 TextView에 있는 스트링을 실수(Double)로 변환하여, 변수 susu에 넣는다. 전달된 파라메터를 변수 operator에 넣는다.

  10. specialPress()– 설명 (2/3) 현재 수(susu)의 제곱근(루트) 값을 구한다. 현재 수(susu)의 백분율을 구한다. 현재 수(susu)의 역수를 구한다. 변수 operator에 따라, 다음을 수행한다.

  11. specialPress()– 설명 (3/3) 소수점 이하를 변수 ii에 저장한다. ii가 0이면, 소수점 이하가 없음을 의미하므로, 맨 뒤에 ‘.’을추가하여 출력한다. ii가 0이 아니면, 소수점 이하가 있음을 의미하므로, 현재 값을 그대로 출력한다. 계산 결과(mAfter)를 결과 창(result)에 출력한다.

  12. specialPress() - 코드

  13. 바르게 동작하는지 확인해 보세요~

  14. 자신만의 계산기로 바꾸어 보세요~ 버튼 모양, 배치, 종류 등을 달리해 본다. 설계/구현한 내용을 데모한다.(1 hour)

More Related