显示默认的日期在部件的EditText [英] Displaying a default date in a EditText widget

查看:153
本文介绍了显示默认的日期在部件的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何显示在窗口小部件的EditText的文本的当前日期在运行时动态?

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

谢谢
帕特里克

Thanks patrick

推荐答案

如果您的EditText在XML文件中声明,你在code这样的检索它

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() ));

这篇关于显示默认的日期在部件的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆