Forum Xamarin.Android

NumberPicker from TimePickerDialog ?

i want to get number picker from timepicker dialoag, i try this but dont work

    private NumberPicker FindMinuteNumberPicker(ViewGroup viewGroup)
            {
                for (var i = 0; i < viewGroup.ChildCount; i++)
                {
                    var child = viewGroup.GetChildAt(i);
                    var numberPicker = child as NumberPicker;
                    var a = child as LinearLayout;
                    if (numberPicker != null)
                    {
                        if (numberPicker.MaxValue == 59)
                        {
                            return numberPicker;
                        }
                    }

                    var childViewGroup = child as ViewGroup;
                    if (childViewGroup != null)
                    {
                        var childResult = FindMinuteNumberPicker(childViewGroup);
                        if (childResult != null)
                            return childResult;
                    }
                }

                return null;
            }

any solution for that ? help me :(

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Based on my test, NumberPicker cannot be accessed by timepicker, Because I used reflect to access the NumberPicker in timepicker, it still get the null object in the minNumberPicker. this numberPicker was created by onDraw method.

                Java.Lang.Class clazz = Java.Lang.Class.ForName("com.android.internal.R$id");
                Java.Lang.Reflect.Field fieldMinutes = clazz.GetField("minute");
                fieldMinutes.Accessible = true;
                int MinutesId = fieldMinutes.GetInt(null);
                NumberPicker minNumberPicker = viewGroup.FindViewById<NumberPicker>(MinutesId);
    
Sign In or Register to comment.