0

In my App i have two TextViews one contains an expression eg. 3 + 4 =

And the second contains an answer eg. 7

How would i go about turning this into a valid maths expression so the app could calculate it and return the answer as an int?

nexus490
  • 797
  • 5
  • 11
  • 21

1 Answers1

0

Depending on the complexity of the expressions you expect in your TextViews, you might need to construct a parser/interpreter for them. If that's the case, I heartily recommend ANTLR. For more information about using ANTLR on Android, see this question.

Another parser generator that I know of is JavaCC, but ANTLR is a lot more flexible and powerful.

Community
  • 1
  • 1
Vojislav Stojkovic
  • 8,043
  • 4
  • 35
  • 48