Reputation: 19
I have two EditTexts that have two different values and a button, on click of that button, result of the multiplication should be displayed in the third Edit Text.
Code Written for the function on the button click:
public void Multiply (View view)
{
String str1 = ed1.getText().toString();
String str2 = ed2.getText().toString();
int num1 = Integer.parseInt(str1);
int num2 = Integer.parseInt(str2);
int prod = num1*num2;
//Toast.makeText(getBaseContext(), "Product is"+(num1*num2),Toast.LENGTH_LONG ).show();
ed3.setText(prod);
}
Upvotes: 0
Views: 929
Reputation: 1756
you can simple add ed3.setText(""+prod);
as edittext directly not accept the integer value.
Upvotes: 0
Reputation: 5914
Use
ed3.setText(String.valueOf(prod));
or
ed3.setText(""+prod);
Upvotes: 1
Reputation: 10059
EditText won't allow integer to go directly in setText
. So convert it into string before setting it
Try this
ed3.setText(String.valueOf(prod));
Upvotes: 0
Reputation: 128428
Mistake:
ed3.setText(prod);
Try:
ed3.setText(String.valueOf(prod));
Upvotes: 2