-3

For example, in a calculator, there are 9 integers on the phone screen and else just like + - / * .... maybe something else. But I want to ask you one question. How can I append the value of keyword of the button to the display. Our developer created the button as text "5". When the user clicks that button, I want to display the 5 value in the edittext without clicking the number 5 value in the built-in keyboard in Android. Can anyone explain how to do this please?

"Keyword" means number 1 - 9 on the keyboard. Normally, when we create the EditText, we can easily input the keyword in EditText by using built-in keyboard. But I don't like it .

Mizuki
  • 2,153
  • 1
  • 17
  • 29
  • Hi, I'm not sure that I understand correctly, but are you looking to create an alternative to the built-in Android keyboard? Anyways, you are more likely to get an answer to your question if you can also provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) illustrating your problem, of course to the extent it is possible. – andybega Oct 25 '15 at 11:55
  • @andybega ... thank you for your suggestion. I give you a simply example. I want to set the value 7 in the edittext when user click the button that I typed as num 7 on display. you see? If you click the button, the edittext must show the value that already assigned. On display, there is button "5", when user click that button, I want to set the value in Edittext as 5 ... thanks – Aung Thu Ya Oct 27 '15 at 04:25

1 Answers1

0

I recommend you to use a TextView instead of EditText to display the numbers. But if you insist, it's also fine. If you look at the docs, you will see there is a setText method in TextView class. And because EditText extends TextView, it will have that as well.

You can use the setText method to set the text of the text view and use getText to get it. That is very simple. In a calculator app, you want to append (which means add something at the end of a string) the number to the existing text, right? So let me show you how to do this.

You can use this code to append "5" to the text view.

String originalText = yourTextView.getText ().toString();
yourTextView.setText (originalText + "5");

Just in case you don't know how to get the TextView:

yourTextView = (TextView)findViewById(R.id.youtTextViewsId);
Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • thanks sweeper, you don't understand what i mean. but I give you example. In calculator app, there is button 1, 2, 3, 4, 5, etc. ok... when the customer click the 1 button, the value of 1 will show the edittext. when the customer click the 2, the value of 2 will show in edtitext. when click 3, value 3 will show in edittext... I want do like that... thanks you... but I dont' know this method... – Aung Thu Ya Oct 27 '15 at 04:35
  • Then you just use the `setText` method to set teh text to 1, 2, 3, 4, 5 etc. @AungThuYa – Sweeper Oct 27 '15 at 05:03