Hello,
Actually, the code of the Formatter
is working.
If you use the following code, you could find the value of day picker has been changed as 01 02...
private void setPickerStyle(DatePicker datePicker)
{
Resources mResources = Resources;
int id = mResources.GetIdentifier("day", "id", "android");
NumberPicker day = (NumberPicker)datePicker.FindViewById(id);
day.SetFormatter(new NumericMonthFormatter());
}
Here's why it doesn't work in the month picker.
On native Android code, in the DatePicker
constructor, the setDisplayedValues
method is called to complete the setting of displaying month data.
At the same time, the value listener of mMonthSpinner
is onChangeListener
, which will call back to the onValueChange
method when the month changes, and the updateSpinners
method will be called in this method, which is another place where the setDisplayedValues
method is called directly.
Calls in these places cause the values of the NumericMonthFormatter
conversion to be overwritten.
Therefore, you need to override those calls to set displayed values, you could refer to SetFormatter method implementation for convert Number to string in Xamarin Android.
If you want to implement this functionality using Formatter
, you need to implement your own DatePicker starting with layout.
numberPicker.SetDisplayedValues(null);
For the month selector, you must set an array of strings with 12 strings.
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.