当前位置:网站首页>DatePickerDialog和trimepickerDialog
DatePickerDialog和trimepickerDialog
2022-07-07 15:40:00 【XLMN】
DatePickerDialog和trimepickerDialog
设置时间对话框和日期对话框
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);
//为设置日期按钮绑定监听器
datebt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar ca = Calendar.getInstance();
//創建一个DatePickerDialog对话框实例,并将他显示出来 //绑定监听器
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(“您选择了:” + year + “年” + (month + 1) + “月” + dayOfMonth + “日”);
}
}
//设置初始日期
, ca.get(Calendar.YEAR),
ca.get(Calendar.MONTH),
ca.get(Calendar.DAY_OF_MONTH)).show();
}
});
//为设置时间按钮设置监听器
timebt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar ca1 = Calendar.getInstance();
//創建一个TimePickerDialog实例并把它显示出来
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("您选择了:" + hourOfDay + "时" + minute + "分");
}
}
//设置初始时间
, ca1.get(Calendar.HOUR_OF_DAY),
ca1.get(Calendar.MINUTE), true
//true采用24小时制
).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="日期选择对话框" />
<Button
android:id="@+id/timebt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="时间选择对话框" />
边栏推荐
- LeetCode 497(C#)
- Flask build API service SQL configuration file
- mysql使用笔记一
- 使用Stace排除故障的5种简单方法
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
- 策略模式 - Unity
- Blue Bridge Cup final XOR conversion 100 points
- A tour of grpc:03 - proto serialization / deserialization
- 服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
猜你喜欢
The top of slashdata developer tool is up to you!!!
【可信计算】第十三次课:TPM扩展授权与密钥管理
【网络攻防原理与技术】第5章:拒绝服务攻击
PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
【TPM2.0原理及应用指南】 5、7、8章
DevOps 的运营和商业利益指南
Nerf: the ultimate replacement for deepfake?
《世界粮食安全和营养状况》报告发布:2021年全球饥饿人口增至8.28亿
【网络攻防原理与技术】第6章:特洛伊木马
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
随机推荐
Jenkins发布uniapp开发的H5遇到的问题
本周小贴士#141:注意隐式转换到bool
Sator launched Web3 game "satorspace" and launched hoobi
From Devops to mlops: how do it tools evolve to AI tools?
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)
LeetCode 515(C#)
LeetCode 403. Frog crossing the river daily
【TPM2.0原理及应用指南】 5、7、8章
Biped robot controlled by Arduino
rpcms获取指定分类下的文章的方法
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
【信息安全法律法规】复习篇
LeetCode1051(C#)
Problems encountered in Jenkins' release of H5 developed by uniapp
如何在博客中添加Aplayer音乐播放器
Flask搭建api服务
SlashData开发者工具榜首等你而定!!!
企业即时通讯软件是什么?它有哪些优势呢?
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展