Xamarin.Android | ComponentOne
Controls / Input / DropDown / Creating a Custom Date Picker using C1DropDown
In This Topic
    Creating a Custom Date Picker using C1DropDown
    In This Topic

    This topic provides you a walkthrough to creating a custom date picker using the C1DropDown control. For this, you begin by creating an Android application, and initializing a C1DropDown, a C1Calendar control, and a C1MaskedTextField control. To create a date picker, you need to set the header property to the object of the MaskedTextField and DropDown property to the object of the C1Calendar class.

    The image below shows how a custom date picker created using the C1DropDown appears.

    Add the following code to the ViewController file to display the control.

    C#
    Copy Code
    public class DropDownActivity : Activity 
       {
            C1DropDown dropdown;
            C1MaskedTextView header;
            C1Calendar calendar;
             
         protected override void OnCreate(Bundle savedInstanceState)
          {
            base.OnCreate(savedInstanceState);
            dropdown = new C1DropDown(this);
            header = new C1MaskedTextView(this);
            header.Mask = Resources.GetString(Resource.String.date_mask_string);
    
            calendar = new C1Calendar(this);
            dropdown.Header = header;
            dropdown.DropDown = calendar;
            dropdown.DropDownHeight = 800;
            dropdown.IsAnimated = true;
    
            calendar.SelectionChanged += (object sender, CalendarSelectionChangedEventArgs e) =>
                            {
            dropdown.IsDropDownOpen = true;
            System.DateTime  dateTime = calendar.SelectedDates[0];
            string strDate = dateTime.ToString(Resources.GetString(Resource.String.date_mask_format));
            header.Value = strDate;
           };
    
           LinearLayout layout = new LinearLayout(this);
           LinearLayout.LayoutParams parameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent);
           layout.AddView(dropdown, parameters);
           SetContentView(layout);
            }
          }