当前位置:网站首页>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="时间选择对话框" />
边栏推荐
- Problems encountered in Jenkins' release of H5 developed by uniapp
- 专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
- Linux 安装mysql8.X超详细图文教程
- Matplotlib绘制三维图形
- 浅谈 Apache Doris FE 处理查询 SQL 源码解析
- On Apache Doris Fe processing query SQL source code analysis
- 【网络攻防原理与技术】第5章:拒绝服务攻击
- Reflections on "product managers must read: five classic innovative thinking models"
- PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
- 第2章搭建CRM项目开发环境(数据库设计)
猜你喜欢
[Seaborn] combination chart: facetgrid, jointgrid, pairgrid
第3章业务功能开发(安全退出)
What is cloud computing?
命令模式 - Unity
鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
Sator launched Web3 game "satorspace" and launched hoobi
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
Linux 安装mysql8.X超详细图文教程
【可信计算】第十三次课:TPM扩展授权与密钥管理
随机推荐
L1-023 输出GPLT(Lua)
L1-027 出租(Lua)
麒麟信安云平台全新升级!
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
L1-019 谁先倒(Lua)
DNS series (I): why does the updated DNS record not take effect?
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
LeetCode 1986. The minimum working time to complete the task is one question per day
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
[Seaborn] implementation of combined charts and multi subgraphs
浅谈 Apache Doris FE 处理查询 SQL 源码解析
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)
[image sensor] correlated double sampling CDs
99%的人都不知道|私有化部署还永久免费的即时通讯软件!
【TPM2.0原理及应用指南】 1-3章
【可信计算】第十二次课:TPM授权与会话
LeetCode 1477. Find two subarrays with sum as the target value and no overlap