Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using 'text fields' with 'person name' I am displaying 'Enter name'. I want the user to enter in this field. AT the same time when the user enters the first character I want to clear the text'Enter name'. Is there any property that could be used to set this or if it has to be done using java, I am submitting here under the code which is not working. Ofcourse I am able to enter the name but the displaying text'Enter name' is just moving to right without disappearing. In properties I have used clickable,editable,enabled and in OnClick I have used 'OnClick' function.


import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.EditText;
import android.app.Activity;

public class listmasteritems extends Activity implements OnClickListener{
public EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listmasteritems);
editText = (EditText)findViewById(R.id.idRelationShip);
editText.setOnClickListener(this);

}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
editText.setText("");
}
Posted

1 solution

Use android:hint attribute in EditText:
Android UI Layouts and Controls[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900