Irakli :
I am new to AndroidStudio. I have managed appending numbers and digits but can't make an addition.
buttonEnter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText numbers = (EditText) findViewById(R.id.numbers);
int ans = 0;
String str1;
String str2;
if (numbers.toString().contains("+")){
str1 = numbers.toString().substring(0, numbers.toString().indexOf('+'));
str2 = numbers.toString().substring(numbers.toString().indexOf('+') + 1,
numbers.length());
ans = Integer.parseInt(str1) + Integer.parseInt(str2);
numbers.setText(Integer.toString(ans));
}
}
});
This is my code for the addition part (haven't tried other operations yet), when I press Enter, the app does nothing.
Nikos Hidalgo :
You're not getting the text from the EditText
. Add the following method at numbers before you do the filtering:
numbers.getText()
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=366614&siteId=1