tags:

views:

127

answers:

2

How would I display the current date in the text of a EditText widget dynamically at runtime?

Thanks patrick

A: 

With updating? Then you'll need a service or something updating the text continuesly!

Snake
I mean an initial value. Let say I have an EditText widget and I want the current date to display in the control when initially displayed. Is there a way to accomplish this in the xml, or programmatically, and what an example might look like.
+3  A: 

If your EditText is declared in the xml file, you have to retrieve it in the code like this

EditText editText = (EditText) findViewById( R.id.your_edittext_id );

Then you can easily update it with the current date

SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" ); 
editText.setText( sdf.format( new Date() ));
kosokund
Thats it! Thanks Thomas