0

I'm trying to clear the contents of an edittext box when it is clicked. Currently my code is as follows:

EditText TextOut1 = (EditText) findViewById(R.id.Search);
TextOut1.setText("", TextView.BufferType.EDITABLE);

This code will change the edittext box when bound to a button, but not when bound to an edit textbox.

acithium
  • 109
  • 1
  • 1
  • 8
  • Figured out that adding android:hint in the layout got what i was looking for "more or less" – acithium Nov 23 '11 at 18:20
  • Possible duplicate of [How to clear an EditText on click?](https://stackoverflow.com/questions/4175398/how-to-clear-an-edittext-on-click) – Stephen Kennedy Oct 02 '18 at 10:42

1 Answers1

0

1)Set the listener on your EditText :

textOut1.setOnFocusChangeListener (this);

2)Let your Activity implements the View.OnFocusChangeListener :

public class MyActivity extends Activity implements View.OnFocusChangeListener{

3)override the method onFocusChange :

public void onFocusChange(View v, boolean hasFocus){

    if(hasFocus){
       EditText TextOut1 = (EditText) findViewById(R.id.Search);
       TextOut1.setText("", TextView.BufferType.EDITABLE);
    }

}
Houcine
  • 24,001
  • 13
  • 56
  • 83