Notice: You have been identified as a bot, so no internal UID will be assigned to you. If you are a real person messing with your useragent, you should change it back to something normal.

Minichan

Topic: Trying to create an Android calculator application.

Handel !khEOdtKF56 started this discussion 15 years ago #13,994

It's for college but each tutorial I look up just confuses me more and more.

Basically the calculator has buttons 0-9, an addition button and a text field to display the results.
I'm able to make the UI and add action listeners to each of the buttons but I have no idea what I should be putting it each buttons action listener.

Any help would be invaluable.

Ks !KansasxqvM joined in and replied with this 15 years ago, 1 minute later[^] [v] #249,462

@OP
> Any help would be invaluable.

Look at existing calculator apps.

Handel !khEOdtKF56 (OP) replied with this 15 years ago, 5 minutes later, 6 minutes after the original post[^] [v] #249,466

@previous (Ks !KansasxqvM)

> Each tutorial I look up just confuses me more and more.

r04r joined in and replied with this 15 years ago, 3 minutes later, 9 minutes after the original post[^] [v] #249,468

Pastebin a code sample of what you currently have, link it here.

Include your layout xml file

(Edited 21 seconds later.)

Ks !KansasxqvM replied with this 15 years ago, 16 minutes later, 25 minutes after the original post[^] [v] #249,472

@249,466 (Handel !khEOdtKF56)
I meant look at the source code of an existing calculator app and see how they do it, it might clear up some things for you.

Here's and open source Android calculator app.
http://code.google.com/p/enh/wiki/Mathdroid

Either way, good luck.

Handel !khEOdtKF56 (OP) replied with this 15 years ago, 3 minutes later, 29 minutes after the original post[^] [v] #249,473

@previous (Ks !KansasxqvM)

Ya I know you're only trying to help sorry for sounding like an asshole. I tried following the link but nothing is standing out at me. This bitch in my course has it already done and she won't even give it to me even though I've helped her with many of her applications. I'm just really pissed off and sleep deprived.

@249,468 (r04r)

http://pastebin.com/T47yAPjH

XML File:

http://pastebin.com/45CUHfrj

I appreciate you having a look at it r04r, you'll probably laugh at my idiocy. :P

(Edited 6 minutes later.)

r04r replied with this 15 years ago, 7 minutes later, 36 minutes after the original post[^] [v] #249,475

@previous (Handel !khEOdtKF56)
Personally I wouldn't use inline OnClickListener's, instead putting `this` there (without the quotes), and implementing OnClickListener on your TuActivity, adding the onClick method and use a switch statement on the id to determine from which button it came, then delegate to other functions which will handle the clicks of buttons 0-9, a function for plus/minutes, etc.

For the handling of the buttons/switch statement see http://code.google.com/p/enh/source/browse/trunk/mathdroid/src/org/jessies/mathdroid/Mathdroid.java#320

For doing the actual math, is kind-of complicated and depends on what kind of math you're expected to do. That's just multiply/devide/plus/minus without grouping, right?

Handel !khEOdtKF56 (OP) replied with this 15 years ago, 4 minutes later, 41 minutes after the original post[^] [v] #249,477

@previous (r04r)

Ya all it needs to do is add/divide, etc. 2 variables.
If you can see from the code what I was hoping to do was once the user clicked add, minus, etc. if would save the variable currently in the text field, then clear the text field and wait until the user entered a second number.

r04r replied with this 15 years ago, 2 hours later, 2 hours after the original post[^] [v] #249,502

@previous (Handel !khEOdtKF56)
Then it's pretty simple. Just keep a variable that is the result, and a variable of the current number and subtract/add the current number from the result and display the result.

Do you have any specific questions?
:

Please familiarise yourself with the rules and markup syntax before posting.