Question

In Android I have the following code to blank an EditText box when clicked. This is to remove any existing information in the box and start with a blank slate. It sort off works. When you first click in the edit box the soft keyboard appears, but the existing information in the EditBox is still there. If you click a second time in the EditBox the information dissapers. How can I get it to clear the data on the first click? I am guessing the first click is intercepted by the soft keyboard. Many thanks for any help.

// Blank EditText field when clicked
        myEditBox.setOnClickListener( new OnClickListener(){

        @Override
        public void onClick(View v) {

            tcA.setText("");
            }

        });
Was it helpful?

Solution

Im not sure, but try clearing it when the EditText gets focus.

myEditBox.setOnFocusChangeListener( new onFocusChangeListener(){
   @Override
   public void onFocusChange(View arg0, boolean hasFocus){
      tcA.setText("");
   }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top