There is an input field. It is cleared as soon as I do the focus there - I start typing text. I click on the field, it is cleared and the keyboard appears. I click, click on the next element - everything is fine. BUT! If I click on the field again, it will be cleared, or there is such an enter or ok button on the keyboard. Pressing it will also clear the field ... How to make it clear only with the first click? Although I came up with a way, it is necessary to make an event when the focus is edited and write to a variable value that cleaning is possible, and if you click on the field, if cleaning = true , then clear.

 etSum.setOnClickListener(this); .... case R.id.etSum: // Ссли ΠΊΠ»ΠΈΠΊ ΠΏΠΎ полю - чистим! etSum.setText(""); Log.d(TAG, "ΠΊΠ»ΠΈΠΊ ΠΏΠΎ полю - чистка"); 

So the question is how to make events when the focus is lost (input is completed) ... or that the field is cleared only with one click on the field ...

  • one
    To clear the field only at the first click, get some flag that will show, this first click or not, if the first click clear (actually, as you wrote). Another thing is that in most cases, when you first click on the field - it is empty ... - s8am
  • And why do you need such a strange behavior? Wouldn't it be better to use a hint (android: hint) instead of text? - Dmitry Guselnikov
  • you need exactly this - to enter constantly different numbers (because the program is a calculator) many times different rates are calculated. - Alex Lizenberg
  • @ s8am yes! exactly! but how to remove this flag? I wanted to shoot it when the field leaves the focus. But how to catch the event that the input is completed and the keyboard is closed - Alex Lizenberg
  • @ AlexLizenberg, Why do you need to shoot it? You only need to install it. Initially, the flag is removed. When you click on the input field, check whether the flag is set: if not set, then clear the input field and set the flag. Everything. (I really did not understand the meaning of all this). - s8am

0