I am a rookie to android. I am thinking of implementing a simple calculator in android to get a hold of the basics in android. I want to display a keypad with numbers and mathematical operations and when the user presses the keys the corresponding number is displayed in edit text. I tried using gettext() and updating the contents of edit text but it shows just the contents of pressed button. Also how do I read the contents of button so as to do mathematical operations in code? Any help would be much appreciated.
regards,
Primal
To set the contents of an EditText:
EditText text = (EditText) findViewById(R.id.your_text);
text.setText("Display this text");
Instead of trying to pull the text off of your buttons and use it as an integer, I would just add a click listener to each one that "knows" the value of its button:
Button button = (Button) findViewById(R.id.num_1);
button.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
// Do something with the value of the button
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With