当前位置:网站首页>DatePickerDialog and trimepickerdialog
DatePickerDialog and trimepickerdialog
2022-07-07 17:37:00 【XLMN】
DatePickerDialog and trimepickerDialog
Set time dialog box and date dialog box
public class MainActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pickerdialog);
Button datebt = findViewById(R.id.datebt);
Button timebt = findViewById(R.id.timebt);
// Bind listeners for the set date button
datebt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar ca = Calendar.getInstance();
// Create a DatePickerDialog Dialog instance , And show him // Bind listener
new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
EditText show = findViewById(R.id.show);
show.setText(“ You chose :” + year + “ year ” + (month + 1) + “ month ” + dayOfMonth + “ Japan ”);
}
}
// Set the initial date
, ca.get(Calendar.YEAR),
ca.get(Calendar.MONTH),
ca.get(Calendar.DAY_OF_MONTH)).show();
}
});
// Set the listener for the set time button
timebt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar ca1 = Calendar.getInstance();
// Create a TimePickerDialog Instance and display it
new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
EditText et = findViewById(R.id.show);
et.setText(" You chose :" + hourOfDay + " when " + minute + " branch ");
}
}
// Set initial time
, ca1.get(Calendar.HOUR_OF_DAY),
ca1.get(Calendar.MINUTE), true
//true use 24 hourly
).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?><EditText
android:id="@+id/show"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/datebt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Date selection dialog " />
<Button
android:id="@+id/timebt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Time selection dialog " />
边栏推荐
猜你喜欢
redis主从、哨兵主备切换搭建一步一步图解实现
textSwitch文本切换器的功能和用法
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
【分布式理论】(二)分布式存储
The top of slashdata developer tool is up to you!!!
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
【TPM2.0原理及应用指南】 1-3章
【信息安全法律法規】複習篇
serachview的功能和用法
麒麟信安中标国网新一代调度项目!
随机推荐
textSwitch文本切换器的功能和用法
L1-023 输出GPLT(Lua)
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
Problems encountered in Jenkins' release of H5 developed by uniapp
【网络攻防原理与技术】第5章:拒绝服务攻击
MRS离线数据分析:通过Flink作业处理OBS数据
【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
LeetCode 648(C#)
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
The mail server is listed in the blacklist. How to unblock it quickly?
数字化转型的主要工作
SlashData开发者工具榜首等你而定!!!
专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
智慧物流平台:让海外仓更聪明
LeetCode刷题day49
无法链接远程redis服务器(解决办法百分百)
【信息安全法律法规】复习篇
[Fantan] how to design a test platform?
第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性