gpt4 book ai didi

android - 如何重置日期选择器

转载 作者:太空宇宙 更新时间:2023-11-03 12:11:43 26 4
gpt4 key购买 nike

我正在 Android 2.1 上开发任务管理器。我想通过单击重置按钮将日期和时间重置为当前日期和时间。帮我写代码..

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText next = (EditText) findViewById(R.id.editText1);
final Button sub = (Button) findViewById(R.id.button1);
final Button res = (Button) findViewById(R.id.button2);
final DatePicker dp= (DatePicker) findViewById(R.id.datePicker1);
final TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);

res.setOnClickListener(new View.OnClickListener() {
public void onClick(final View view) {
next.setText("");
dp.refreshDrawableState();
}
});
}}

最佳答案

//get current time
Time now = new Time();
now.setToNow();

//update the TimePicker
tp.setHour(now.hour);
tp.setMinute(now.minute);

//update the DatePicker
dp.updateDate(now.year, now.month, now.monthDay);

关于android - 如何重置日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8252759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com