There are three very simple ways to solve:
1) Add the attribute below in your Edittext and avoid unwanted characters:
android:inputType="number"
2) Use the methods of the String class itself:
EditText editTextView = (EditText) findViewById(R.id.editTextView);
String myEditValue = editTextView.getText().toString();
//Removendo caracteres indesejados
myEditValue.replace("(", "");
myEditValue.replace("+", "");
int equação = Integer.parseInt(myEditValue);
editTextView.setText(equação + "CERTO!");
3) Search a little about Regex, which is a String used to validate other Strings and if the user enters an unwanted character, show him a message. There is the method of the String class mEditValue.replaceAll(String regex, String substituta)
, that with Regex prevents you from using step 2 for all cases.
Good Luck.
You’re saying it’s wrong inside the setText?
– viana
That is the mistake
;
ai after you close the parentheses, you don’t need it– Leonardo Dias
It has to stay that way
editTextView.setText(equação + "CERTO!")
– Leonardo Dias
Friend the error occurs because if you have a ( or else + or any other character you will not recognize as an integer in the conversion
– Anderson Henrique
Anderson Henrique , there is then some way to recognize this " (6*2)+7+5 " all as an int ?
– Eduardo Brito
No. You have to split and parse each installment individually and do the operations between each thing. Or use a library for that purpose
– Isac
You are trying to implement a "String Calculator". This is not directly supported by the language and, as Isac said, you will need to perform the entire String Stop manually and then perform the calculations, taking operator precedence and so on. You can search for something ready or search tutorials on the Internet, since this is a common 'exercise'.
– Miguel Fontes
I’ll try to find out if I can get the effect I want. I initially thought it was quite simple, it was enough to stop the whole string, but then I came across this error. In the rest of my code there is a series of equations that use these characters and I had no problem, this because I have always worked with int’s. So either I find another method to get the equations or I have to do as you said. I’ll try to see Thanks for the help
– Eduardo Brito