-1

I want the user to tap on an Edit text operations, such as 1+3-5 then he/she press for long to get the result? my issue is that how can I let the app differentiates between numbers and operations(+,-,*)?

humazed
  • 74,687
  • 32
  • 99
  • 138
  • I am trying to create a simple calculator, the user should enter 3+7+5 then long press and the app should presents the result on the EditText. – Alnfiai Mar 27 '16 at 03:20
  • you should use the regular expression I'm trying a method to do what you want. – humazed Mar 27 '16 at 03:29

1 Answers1

0

you can use code like this.

    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine engine = mgr.getEngineByName("JavaScript");
    String foo = "(40+2)*10";
    try {
        System.out.println(engine.eval(foo));
    } catch (ScriptException e) {
        e.printStackTrace();
    }

but be aware that this method doesn't follow the presence of mathematical operations.

but this library or that do.

for further reading take a look at this question.

Community
  • 1
  • 1
humazed
  • 74,687
  • 32
  • 99
  • 138