当前位置:网站首页>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 1774. The dessert cost closest to the target price is one question per day
- 麒麟信安云平台全新升级!
- 如何在软件研发阶段落地安全实践
- Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
- 鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
- L1-025 正整数A+B(Lua)
- 如何在博客中添加Aplayer音乐播放器
- mysql使用笔记一
- Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
- SlashData开发者工具榜首等你而定!!!
猜你喜欢
随机推荐
【TPM2.0原理及应用指南】 12、13、14章
LeetCode 1986. The minimum working time to complete the task is one question per day
Establishment of solid development environment
浅谈 Apache Doris FE 处理查询 SQL 源码解析
Flash build API Service - generate API documents
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
【网络攻防原理与技术】第5章:拒绝服务攻击
Flask build API service SQL configuration file
NeRF:DeepFake的最终替代者?
Blue Bridge Cup final XOR conversion 100 points
Leetcode brush questions day49
Sator推出Web3游戏“Satorspace” ,并上线Huobi
Seaborn data visualization
[Fantan] how to design a test platform?
自定义View必备知识,Android研发岗必问30+道高级面试题
第3章业务功能开发(安全退出)
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
【TPM2.0原理及应用指南】 5、7、8章
Mysql 索引命中级别分析
Nerf: the ultimate replacement for deepfake?









