Clear text in EditText when entered
First you need to call setContentView(R.layout.main)
then all other initialization.
Please try below Code.
public class Trackfolio extends Activity implements OnClickListener {
/** Called when the activity is first created. */
public EditText editText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText) findViewById(R.id.editText1);
editText.setOnClickListener(this);
}
@Override
public void onClick(View v) {
editText.getText().clear(); //or you can use editText.setText("");
}
}
how to clear EditText in Android?
Add this code to clear all your editText :
morning.setText("");
noon.setText("");
afternoon.setText("");
night.setText("");
before_meal.setText("");
after_meal.setText("");
hourly.setText("");
days.setText("");
How to clear the string in the editText when clicking on it
Instead of doing that, you can specify the following using hint
In your layout xml file , under your EditText
, add this
android:hint="Enter your text here"
This will appear on your edit text when you start the activity and disappears when user have clicked on it
How can I automatically clear the text in EditText?
What you're referring to isn't actually text that's being set -- it's a hint (which is why it doesn't show after the EditText is focused or text has already been entered). You can set these placeholder hints in your EditText XML, for example:
android:hint="First Name".
If you're feeling really adventerous, you can also wrap your EditText in a TextInputLayout for a Material Design style floating hint.
If that helps, be sure to accept this answer.
Clearing previously entered text in EditText field
Errr...
The only code I use to achieve 1) is:
// Clear text when clicked
host.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
host.setText("");
}
});
host
just being an EditText. Works just fine? I think you are making this more complicated than it is.
EditText clear text on first focus - Android
Matan, I am not sure if this is what you are looking at, but I think you want to display a 'hint' for your Edit Text
Example
<EditText
.
.
android:hint="Please enter your name here">
For an example check this http://www.giantflyingsaucer.com/blog/wp-content/uploads/2010/08/android-edittext-example-3a.jpg
Related Topics
Android Activity Has Leaked Window Com.Android.Internal.Policy.Impl.Phonewindow$Decorview Issue
Textinputlayout :How to Give Padding or Margin to Hint
How to Send Notification to Specific Users with Fcm
How to Programmatically Launch a Specific Application
Volley Out of Memory Error, Weird Allocation Attempt
Change Text Color of Selected Item in Spinner
Message "Error: Resource Android:Attr/Lstar Not Found"
Findviewbyid() Returns Null for Views in a Dialog
How to Connect SQL Server Using Jtds Driver in Android
How to Change Screen Orientation in the Android Emulator
Libz.So.1: Cannot Open Shared Object File
Two Textviews Side by Side, Only One to Ellipsize
How to Tell Which App Was Selected by Intent.Createchooser
How to Know When Tts Is Finished
How to Get HTML Source Code from Url in Android
Android Viewpager Setcurrentitem Not Working After Onresume
Android Unknown Command 'Crunch'
I Have Forgotten My Keystore Password and I Want to Install My APK on Google Play. What Do I Do