Android how to write onclick edittext event

I have text editText text. Enter ur name .. so I want when the user just clicks on this editText, then the text will disappear and editText should be empty and the user can write something of his own. so how can i do that. plz give me ans

+3
source share
4 answers

For your requirement, you do not need an onClick event listener.

try it

 <EditText
                android:hint="Enter you name"
                android:id="@+id/editText"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"></EditText>

or from java code

editText.setHint("Enter you name");
+6
source
 final EditText edittxt = (EditText) findViewById(R.id.youredittext);
    edittxt.setOnFocusChangeListener(new OnFocusChangeListener()
    {
        @Override
        public void onFocusChange(View v, boolean hasFocus) 
        {
            if (hasFocus == true)
            {
                if (edittxt.getText().toString().compareTo("Your hint") == 0) // default text
                {
                    edittxt.setText("");
                }
            }
        }
    });
+8
source

..

editText.setOnClickListener(new OnClickListener(){
    public void onClick(View v){
        ((EditText)v).setText("");
    }
});
+1

android:hint = "text that you want the user to be assisted with while typing" .

EditText, autocompleteText view, android monodroid.

+1

All Articles