当前位置:网站首页>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 " />
边栏推荐
- mysql实现两个字段合并成一个字段查询
- The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
- 【TPM2.0原理及应用指南】 12、13、14章
- What is cloud computing?
- Matplotlib绘制三维图形
- serachview的功能和用法
- 【信息安全法律法规】复习篇
- 【网络攻防原理与技术】第1章:绪论
- Functions and usage of viewflipper
- 【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用
猜你喜欢
随机推荐
Matplotlib绘制三维图形
【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用
在窗口上面显示进度条
alertDialog創建对话框
跟奥巴马一起画方块(Lua)
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
麒麟信安加入宁夏商用密码协会
第3章业务功能开发(实现记住账号密码)
【TPM2.0原理及应用指南】 12、13、14章
Nerf: the ultimate replacement for deepfake?
The top of slashdata developer tool is up to you!!!
第3章业务功能开发(用户访问项目)
Rpcms method of obtaining articles under the specified classification
【TPM2.0原理及应用指南】 5、7、8章
On Apache Doris Fe processing query SQL source code analysis
Notes on installing MySQL in centos7
无法链接远程redis服务器(解决办法百分百)
Leetcode brush questions day49
notification是显示在手机状态栏的通知
L1-023 输出GPLT(Lua)