Ric Cristof wrote:
1 - Decimal place. Double handles that just fine. I have a friend that used Float and got a large number on the answer.
2 - Yeah.... I noticed that after looking for a while on the Internet. It would be waaaay easier to use onClick on the XML. You're right. I just used the hard way - more coding, less design.
3 - You got me on that one. Had to look out. Thanks for asking. ((Button) v).getText().toSring(); it says that cannot resolve the method .toString();. Still, I understand that .getText() gets the information from the button instead of .toString(); where it gets the info from the XML. (Come to think about, I could really used that instead of my method...)
I made a few changes since yesterday and will post later updating the post.
1. Double has twice the precision of float. While neither is accurate, for your calculator, i doubt it matters. Just round the (longer) numbers. Do a google search for "
what every computer scientist should know about floating point"
2. Heh. So many books don't even teach this method, instead showing callbacks and what you did. BTW, there's another way i found, and i'm using in my current project:
- In the class declaration, add: implements View.OnClickListener
- In the class block implement: public void onClick(View view){}
- for the button: button.setOnClickListener(this);
The "this" refers to the class, as you'd expect, making it search for the onClick(). It works well in my scenario because i am creating a bunch of buttons dynamically.
3. Oops! Android Studio didn't allow me to mess with the code because it wasn't part of my project. Based on the (String) i just assumed that it needed to be cast, in which case, there's probably be a toString(). There usually is.
When you post again, please use the code tags. The "Code" button on top of the editor window will make it look nice and pretty, keep formatting, making it much easier to read.