Detailed explanation of Android time dialog box

1、 Introduction

2、 Method

1) Show timepickerdialog method

1. New timepickerdialog object

TimePickerDialog timeDialog=new TimePickerDialog(this,new MyTimeSetListener(),13,30,true);

The meanings of each parameter are as follows:

Explain:

The first parameter, context, is the parent control displayed by the control, that is, the control in which the control is displayed

The second parameter callback is that after the control appears, there will be a set or done button on the control. After you click this button, the monitor will be called.

So here I write a listener, new mytimesetlistener(), whose source is as follows:

Public class mytimesetlistener implements ontimesetlistener {which overrides the parent ontimeset method}

That is, the implemented ontimesetlistener interface

In fact, you can also directly use the object of ontimesetlistener. The code is as follows:

Public ontimesetlistener timesetlistener = newontimesetlistener() {which overrides the parent ontimeset method}

2. Call the show() method of the timepickerdialog object

timeDialog.show();

The show method is not written, and the screen does not respond

2) Show DatePickerDialog method

The method is as like as two peas TimePickerDialog, and the method is very similar.

If you don't understand, look directly at the code example

3、 Code example

design sketch:

After clicking timepickerdialog

Click Done

Click "display DatePickerDialog"

After clicking done

code:

fry.Activity01

/Ex25ClockDemo/res/layout/activity01.xml

4、 Attention

1. Set the dial property in analogclock. Of course, the pointer can also be set by itself

Clock setting: Android: hand_ Hour minute hand setting: Android: hand_ minute

2. The initialization method of timepickerdialog needs special attention, especially the description of various parameters

3. Don't forget that the newly created timepickerdialog object must call the show () method, or it won't be displayed at all

In fact, almost all such controls displayed on another control must call the show () method to display, for example:

TimePickerDialog、DatePickerDialog、Toast

4. If you want to know when the second parameter new mytimesetlistener() in the initialization method of timepickerdialog is used,

In fact, just test it with log or toast

5、 Error prone point

1. Don't forget that the newly created timepickerdialog object must call the show () method, or it won't be displayed at all

timeDialog.show();

This is easy to forget and easy to make mistakes

In fact, almost all such controls displayed on another control must call the show () method to display, for example:

TimePickerDialog、DatePickerDialog、Toast

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>