I am new to Android development and am working on a simple practice project where the user enters a number into two EditText fields and presses a Button labeled “Calculate” and the sum of the two numbers is displayed. Here is the code I have so far, but I don’t know how to add the two string values and output it to a TextView field named “answer”:
public void calNumbers(View view) {
EditText text = (EditText)findViewById(R.id.edit_number1);
String value = text.getText().toString();
EditText text2 = (EditText)findViewById(R.id.edit_number2);
String value2 = text2.getText().toString();
TextView answer = (TextView) findViewById(R.id.answer);
}
You’ll have to convert them to numbers (int, float, long, etc) to preform your arithmetic. Then convert the result back to a String to display in a TextView