This article GitHub code links
Https://github.com/AndroidMsky/AndoirdIOSPicker
Let's go ahead and figure it out:
This is the author of a recent project has been used a selector library, and I have made changes in it, and decided to continue to maintain.
See how to use First:
Date selection:
private void Showdatedialog (list<integer> date) {
Datepickerdialog.builder Builder = new Datepickerdialog.builder (this);
Builder.setondateselectedlistener (New Datepickerdialog.ondateselectedlistener () {
@Override public
Void Ondateselected (int[] dates) {
mtextview.settext (Dates[0] + "-" + (Dates[1] > 9? dates[1]: ("0" + dates[1]) + "-"
+ (Dates[2] > 9 dates[2]: ("0" + dates[2]
)) @Override public
void OnCancel () {
}
}).
setminyear (1900).
setmaxyear (2050)
. Setselectyear (date.get (0)-1)
. Setselectmonth (Date.get (1)-1)
. Setselectday (Date.get (2)-1);
Builder.setmaxyear (Dateutil.getyear ());
Builder.setmaxmonth (Dateutil.getdateforstring (Dateutil.gettoday ()). Get (1));
Builder.setmaxday (Dateutil.getdateforstring (Dateutil.gettoday ()). Get (2));
Datedialog = Builder.create ();
Datedialog.show ();
}
It's easier to explain.
Custom selections:
Let's get a list.
Private list<string> List = new arraylist<> ();
And then the call will pass through the list.
/**
* Choosedialog * *
private void Showchoosedialog (list<string> mlist) {
Datapickerdialog.builder Builder = new Datapickerdialog.builder (this);
Choosedialog = Builder.setdata (mlist). SetSelection (1). Settitle ("Cancel")
. Setondataselectedlistener (New Datapickerdialog.ondataselectedlistener () {
@Override public
void ondataselected (String itemvalue, int Position) {
mtextview.settext (itemvalue);
}
@Override public
void OnCancel () {
}
}). Create ();
Choosedialog.show ();
}
And then we're going to do the timepick. Simple analysis of the principle of the following, but also facilitate our custom extension.
First open Timepickerdialog visible inheritance from dialog to custom dialog is not familiar to see:
Android Builder Mode Resolution + custom Dialog actual walkthrough
http://blog.csdn.net/androidmsky/article/details/52982815
public class Timepickerdialog extends Dialog
Sure this dialog will use the builder mode, then look inside the field
Private static Final class Params {
private Boolean Shadow = True;
Private Boolean cancancel = true;
Private Loopview Loophour, loopmin;
Private Ontimeselectedlistener callback;
}
See the main force is two loopview to represent the hours and minutes, then we will see loopview this kind of, go in will find a larger face parameters. Don't be afraid, we come directly to its two most critical methods,
You can see it is to draw out the words do not be afraid of back and forth on so several ways:
The core is it
Canvas.drawtext (as[j1], StartX, H, PAINTB);
Calling it in several cases is definitely 12,345 different styles of numbers
if (i2 <= n && H + i2 >= N) {
canvas.save ();
Canvas.cliprect (0, 0, V, n-i2);
Canvas.drawtext (As[j1], StartX, H, Painta);
Canvas.restore ();
Canvas.save ();
Canvas.cliprect (0, N-i2, V, (int) ((float) H * l));
Canvas.drawtext (As[j1], StartX, H, PAINTB);
Canvas.restore ();
} else if (i2 <= o && H + i2 >= o) {
canvas.save ();
Canvas.cliprect (0, 0, V, o-i2);
Canvas.drawtext (As[j1], StartX, H, PAINTB);
Canvas.restore ();
Canvas.save ();
Canvas.cliprect (0, O-i2, V, (int) ((float) H * l));
Canvas.drawtext (As[j1], StartX, H, Painta);
Canvas.restore ();
} else if (i2 >= n && H + i2 <= o) {
canvas.cliprect (0, 0, V, (int) ((float) H * l));
Canvas.drawtext (As[j1], StartX, H, PAINTB);
Mselectitem = Arraylist.indexof (as[j1]);
} else {
canvas.cliprect (0, 0, V, (int) ((float) H * l));
Canvas.drawtext (As[j1], StartX, H, Painta);
Canvas.restore ();
The next key approach is:
public boolean ontouchevent (Motionevent motionevent)
Change the plotted offset value by moving the finger:
Case Motionevent.action_move:
y = Motionevent.getrawy ();
z = x-y;
x = y;
totalscrolly = (int) ((float) totalscrolly + z);
if (!isloop) {
if (totalscrolly > (int) ((float) (-positon) * (L * (float) h)) {break
;/* Loop/switch isn ' t C ompleted */
}
totalscrolly = (int) ((float) (-positon) * (L * (float) h);
}
Break
This is probably the position to see Open source Custom view.
The above is a small set of Android development to introduce the implementation of iOS style bottom selector (support time and date customization), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!