I am new to Android development and currently learning to design for a basic calculator app. I have already self designed the layout, but sourced Main Activity codes from different websites for the operations for 0 to 9, +, -, *, / and after incorporation, they work fine.
However, I do want to further modify the MainActivity with decimal point function. While integer can be shown properly to the screen using "current = current * 10 + number", eg 53 = 5*10+3;
I am thinking applying the same approach for decimal point with a loop function, the idea like this: 1. current = current + remaining if dot button is pressed 2. create an integer i, i increases by 1 once any numerial button is clicked 3. so that when e.g. input 5.3, i =1, it will = 5 + 3/(10^i) = 5.3 4. 5.3 loop to here, then when e.g. input as 5.39, now i=2, it will = 5.3 + 9/(10^i) = 5.39
QUESTION >> *Yet...really...I am so fresh that I do not know how to design the coding for the decimal button, would there be anyone can suggest the code?* first ignore the following addons where errors to be detected (such as delete the second dot if the dot is input twice or more, adding 0 in front of . if say, .5 is input)
The button id is as follows, and once clicked to refer to DecimalClickEvent Button b_decimal = (Button) findViewById(R.id.decimal); b_decimal.setOnClickListener(new DecimalClickEvent(???));}
Many many thanks in advance!! The codes are attached below for reference and your comments:
ฉันใหม่เพื่อการพัฒนา Android และขณะนี้การเรียนรู้ในการออกแบบสำหรับ app เครื่องคิดเลขขั้นพื้นฐาน ผมมีอยู่แล้วในตัวเองได้รับการออกแบบรูปแบบ แต่ที่มารหัสกิจกรรมหลักจากเว็บไซต์ที่แตกต่างกันสำหรับการดำเนินงานสำหรับ 0-9, +, -, *, / และหลังจากที่ บริษัท ที่พวกเขาทำงานได้ดี. แต่ผมไม่ต้องการที่จะเพิ่มเติมแก้ไข MainActivity ด้วย ฟังก์ชั่นจุดทศนิยม ในขณะที่จำนวนเต็มสามารถแสดงได้อย่างถูกต้องไปยังหน้าจอการใช้ "ปัจจุบัน = ปัจจุบัน * 10 + หมายเลข" เช่น 53 = 5 * 10 + 3 ผมคิดว่าการใช้วิธีการเดียวกันสำหรับจุดทศนิยมมีฟังก์ชั่ห่วงความคิดเช่นนี้: 1 . ในปัจจุบัน = ปัจจุบัน + ที่เหลือถ้าปุ่มกดจุด 2. สร้างจำนวนเต็มฉันฉันเพิ่มขึ้น 1 ครั้งเดียวปุ่มใด ๆ numerial คลิก 3. เพื่อที่ว่าเมื่อเช่นการป้อนข้อมูล 5.3 i = 1 ก็จะ = 5 + 3 / (10 ^ i) = 5.3 5.3 4. ห่วงที่นี่แล้วเมื่อป้อนข้อมูลเช่นเป็น 5.39, ตอนนี้ฉัน = 2 ก็จะ = 5.3 + 9 / (10 ^ i) = 5.39 คำถาม >> * แต่ ... จริงๆ ... ผมสดเพื่อที่ฉันไม่ทราบวิธีการออกแบบการเขียนโปรแกรมสำหรับปุ่มทศนิยมจะมีใครสามารถแนะนำรหัส * ครั้งแรกไม่สนใจ addons ต่อไปที่ข้อผิดพลาดที่จะตรวจพบ (เช่นลบจุดที่สองถ้าจุดคือ . ป้อนข้อมูลสองครั้งหรือมากกว่าการเพิ่ม 0 ในด้านหน้าของถ้าพูด, 0.5 คือการใส่) รหัสปุ่มดังต่อไปนี้และเมื่อคลิกที่จะอ้างถึง b_decimal ปุ่ม DecimalClickEvent = (ปุ่ม) findViewById (R.id.decimal); b_decimal.setOnClickListener (DecimalClickEvent ใหม่ (???));} ขอบคุณมากมากล่วงหน้า !! รหัสที่แนบมาด้านล่างสำหรับการอ้างอิงและแสดงความคิดเห็นของคุณ:
การแปล กรุณารอสักครู่..
