Android implements custom date selector based on wheelview

This example shares the specific code for Android to realize custom date selector for your reference. The specific contents are as follows

Renderings of project requirements:

It is required that "Friday, June 20" can be sliding as a whole, "7:00" and "48:00" can be sliding as a whole respectively.

As we all know, the datepicker and TimePicker provided by the system only have this effect:

Baidu has tried a lot, but it can't even try numberpicker. I was going to write it myself. Netizens recommended an open source component wheelview. After trying it, they found that it has been well defined and it is easy to expand on its basis.

The custom date selector based on wheelview is recorded as follows:

1、 First, we need to understand what wheelview provides us:

Except for "dateobject" and "stringwheeladapter" I wrote, the rest are provided by wheelview,

1. Wheelview.java: scrollable component

Main methods:

2. Wheeladapter.java: interface of adapter of sliding component. Subclass adapter is used to load data

3. Onwheel changedlistener.java: sliding listener interface

4. Onwheel scrolllistener.java: scroll listener interface (not used temporarily)

5. Numericwheeladapter.java: the adapter called when the scrolling content is pure number

6. Dateobject.java: Date entity class, used to store and obtain selected data

7. Stringwheeladapter.java: the defined scrolling content will be the adapter of the string later. When the content is the string, we can expand the content of the sliding part at will

2、 After understanding, we can use it to define what we need.

1. The first thing to do is the part of this effect:

We named it datepicker:

2. What to do next is the part of this effect

We named it TimePicker:

3. Finally, you can use it directly. The main interface here is a button. Click it to pop up the popupwindow to display the date selector. The layout file and main activity are as follows:

Popupwindow layout file:

Main interface layout file:

Activity Code:

Final rendering:

Source download: Android implements a custom date selector

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
分享
二维码
< <上一篇
下一篇>>