当前位置:网站首页>Dateticket and timeticket, functions and usage of date and time selectors
Dateticket and timeticket, functions and usage of date and time selectors
2022-07-07 17:36:00 【XLMN】
datepicket and timepicket, date 、 Function and usage of time selector
Both are derived from framelayout Derived from ,datepicket For users to choose a date ,timepicket For the user to choose the time
datapicket adopt ondatechangedlistener monitor ,timepicket By adding ontimerchangedlistener monitor
public class MainActivity extends Activity {
// Definition 5 A variable that records the current time
private int year;
private int month;
private int day;
private int hour;
private int minute;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.picket);;
DatePicker dp=findViewById(R.id.datapicket);
TimePicker tp=findViewById(R.id.timepicker);
// Get the current month, day, hour, minute
Calendar ca=Calendar.getInstance();
year=ca.get(Calendar.YEAR);
month=ca.get(Calendar.MONTH);
day=ca.get(Calendar.DATE);
hour=ca.get(Calendar.HOUR);
// initialization DATApicker Components , Specify the listener when initializing
dp.init(year, month, day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int month, int day) {
MainActivity.this.year=year;
MainActivity.this.month=month;
MainActivity.this.day=day;
// Display the current date time
showDate(year,month,day,hour,minute);
}
});
// by timepicker Specify the listener
tp.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
MainActivity.this.hour=hourOfDay;
MainActivity.this.minute=minute;
// Display the current date time
showDate(year,month,day,hour,minute);
}
});
}
private void showDate(int year,int month,int day ,int hour,int minute) {
EditText et=findViewById(R.id.show);
et.setText(" The current date is :"+year+" year "+month+" month "+day+" Japan "+hour+" when "+minute+" branch , Is the beginning of good luck ");
}
}
<?xml version="1.0" encoding="utf-8"?><TimePicker
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"
android:id="@+id/timepicker"/>
<!-- A control that displays the date and time entered by the user -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:cursorVisible="false"
android:id="@+id/show"/>
边栏推荐
- [fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
- 字符串 - string(Lua)
- Jenkins发布uniapp开发的H5遇到的问题
- mysql使用笔记一
- 智慧物流平台:让海外仓更聪明
- Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
- imageswitcher的功能和用法
- 【TPM2.0原理及应用指南】 5、7、8章
- The top of slashdata developer tool is up to you!!!
- centos7安装mysql笔记
猜你喜欢
随机推荐
notification是显示在手机状态栏的通知
【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用
麒麟信安加入宁夏商用密码协会
[fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
alertDialog創建对话框
datepicket和timepicket,日期、时间选择器的功能和用法
浅谈 Apache Doris FE 处理查询 SQL 源码解析
viewflipper的功能和用法
Enum + Validation 的个人最佳实践 demo 分享
LeetCode 515(C#)
L1-023 输出GPLT(Lua)
DatePickerDialog和trimepickerDialog
How to mount the original data disk without damage after the reinstallation of proxmox ve?
到底有多二(Lua)
【信息安全法律法規】複習篇
LeetCode 648(C#)
科普达人丨一文弄懂什么是云计算?
【分布式理论】(一)分布式事务
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
Mysql 索引命中级别分析