Reputation: 4055
How do you remove the default text you assign a <editText>
when the user focuses on that text box?
I found the code below that looks like it should work but when I click on the text box I still have to delete the default text before typing new text.
final EditText RemoveZipField = (EditText) findViewById(R.id.zipcode);
RemoveZipField.setOnFocusChangeListener(new OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus==true)
{
if (RemoveZipField.getText().toString().compareTo("Zipcode")==0)
{
String inText = "I AM IN";
Log.d(TAG, inText);
RemoveZipField.setText("");
}else{
String outText = "I AM OUT";
Log.d(TAG, outText);
}
}
}
});
Upvotes: 2
Views: 4130
Reputation: 11408
Instead of adding "default text" to the EditText, why don't you just use the built in hint functionality?
It can be specified in XML like this:
<EditText
<!-- layout width/height code -->
android:hint="Phone Number"
/>
Upvotes: 14