protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.queryrouteview);

            var startRegion  = FindViewById <Spinner>(Resource.Id.queryrouteview_startregion);
            var startAirport = FindViewById <Spinner>(Resource.Id.queryrouteview_startairport);
            var endRegion    = FindViewById <Spinner>(Resource.Id.queryrouteview_endregion);
            var endAirport   = FindViewById <Spinner>(Resource.Id.queryrouteview_endairport);

            var    btnAirport = FindViewById <Button> (Resource.Id.queryrouteview_btnairport);
            string text       = Intent.GetStringExtra("feature");

            int next = -1;

            if ("flight" == text)
            {
                next            = 0;
                btnAirport.Text = "查詢航線資訊";
            }
            else if ("airport" == text)
            {
                next            = 1;
                btnAirport.Text = "查詢機場報到資訊";
            }
            else
            {
                btnAirport.Enabled = false;
            }


            btnAirport.Click += (object sender, EventArgs e) => {
                FinalRoute.Flights = new FlightInfoManager().ReadFlightByRouteId(FinalRoute.Id);

                var routeString = Newtonsoft.Json.JsonConvert.SerializeObject(FinalRoute);

                if (0 == next)
                {
                    RunOnUiThread(() => {
                        var detailView = new Intent(this, typeof(QueryRouteResultActivity));
                        detailView.PutExtra("route", routeString);
                        StartActivity(detailView);
                    });
                }
                else if (1 == next)
                {
                    RunOnUiThread(() => {
                        var detailView = new Intent(this, typeof(QueryRouteCheckInfoActivity));
                        detailView.PutExtra("route", routeString);
                        StartActivity(detailView);
                    });
                }
            };

            //
            SelectedRoutes            = new List <Route> ();
            AirportsNameInStartRegion = new List <string> ();
            StopRegions = new List <Region> ();
            AirportsNameInStopRegion = new List <string> ();

            //
            FlightManager = new FlightInfoManager();
            var routes = FlightManager.ReadRouteFromRemote();

            //

            startRegion.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, FlightManager.ReadRegions());

            startRegion.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
                var list = routes.Where(route => route.StartAirport.GeoRegion == (Region)e.Position).ToList();
                AirportsNameInStartRegion.ClearThenAddRange(list.Select(r => r.StartAirport.Name).Distinct().ToList());
                startAirport.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, AirportsNameInStartRegion);
            };


            startAirport.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
                //
                _startAirportName = AirportsNameInStartRegion[e.Position];


                SelectedRoutes.ClearThenAddRange(routes.Where(r => r.StartAirport.Name == _startAirportName).ToList());

                StopRegions.ClearThenAddRange(SelectedRoutes.Select(r => r.StopAirport.GeoRegion).Distinct().ToList());

                var list = new List <string>();

                foreach (var region in StopRegions)
                {
                    list.Add(region.ToString());
                }

                endRegion.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, list);
            };

            endRegion.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
                _selectedRegion = StopRegions[e.Position];

                var temp = routes.Where(r => r.StartAirport.Name == _startAirportName && r.StopAirport.GeoRegion == _selectedRegion).ToList();

                AirportsNameInStopRegion.ClearThenAddRange(temp.Select(r => r.StopAirport.Name).Distinct().ToList());

                endAirport.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, AirportsNameInStopRegion);
            };

            endAirport.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
                var airportName = AirportsNameInStopRegion[e.Position];

                var list = routes.Where(r => r.StartAirport.Name == _startAirportName && r.StopAirport.GeoRegion == _selectedRegion && r.StopAirport.Name == airportName).ToList();

                if (1 == list.Count)
                {
                    FinalRoute = list[0];
                }
            };
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //
            SelectedRoutes            = new List <Route> ();
            AirportsNameInStartRegion = new List <string> ();
            StopRegions = new List <Region> ();
            AirportsNameInStopRegion = new List <string> ();

            //
            FlightManager = new FlightInfoManager();
            var routes = FlightManager.ReadRouteFromRemote();

            //
            var    regions      = FlightManager.ReadRegions();
            Region seletedRegin = Region.NorthAmerica;

            var airportList = routes.Where(route => route.StartAirport.GeoRegion == seletedRegin).ToList();

            AirportsNameInStartRegion.ClearThenAddRange(airportList.Select(r => r.StartAirport.Name).Distinct().ToList());
            _startAirportName = AirportsNameInStartRegion[0];

            startRegion.SetTitle(regions [0], UIControlState.Normal);
            startAirport.SetTitle(_startAirportName, UIControlState.Normal);

            CurrentModel              = new RoutePickerViewModel(regions);
            pickerView.Model          = CurrentModel;
            CurrentModel.RowSelected += (object picker, RowSelectedEventArgs args) => {
                InvokeOnMainThread(() => {
                    pickerView.Hidden = true;
                    btnAirport.Hidden = false;
                });
            };

            //

            startRegion.TouchUpInside += (object sender, EventArgs e) => {
                CurrentModel              = new RoutePickerViewModel(FlightManager.ReadRegions());
                pickerView.Model          = CurrentModel;
                CurrentModel.RowSelected += (object picker, RowSelectedEventArgs args) => {
                    seletedRegin = (Region)args.SelectedIndex;

                    var list = routes.Where(route => route.StartAirport.GeoRegion == seletedRegin).ToList();
                    AirportsNameInStartRegion.ClearThenAddRange(list.Select(r => r.StartAirport.Name).Distinct().ToList());


                    _startAirportName = AirportsNameInStartRegion[0];

                    InvokeOnMainThread(() => {
                        pickerView.Hidden = true;
                        btnAirport.Hidden = false;

                        startRegion.SetTitle(args.SelectedTitle, UIControlState.Normal);
                        startAirport.SetTitle(_startAirportName, UIControlState.Normal);
                        //
                    });
                };

                InvokeOnMainThread(() => {
                    pickerView.Hidden = false;
                    btnAirport.Hidden = true;
                });
            };

            startAirport.TouchUpInside += (object sender, EventArgs e) => {
                var list = routes.Where(route => route.StartAirport.GeoRegion == seletedRegin).ToList();
                AirportsNameInStartRegion.ClearThenAddRange(list.Select(r => r.StartAirport.Name).Distinct().ToList());
                //



                //
                CurrentModel              = new RoutePickerViewModel(AirportsNameInStartRegion);
                pickerView.Model          = CurrentModel;
                CurrentModel.RowSelected += (object picker, RowSelectedEventArgs args) => {
                    // Default Stop Region
                    _startAirportName = args.SelectedTitle;
                    SelectedRoutes.ClearThenAddRange(routes.Where(r => r.StartAirport.Name == _startAirportName).ToList());
                    StopRegions.ClearThenAddRange(SelectedRoutes.Select(r => r.StopAirport.GeoRegion).Distinct().ToList());

                    var stopRegionNameList = new List <string>();

                    foreach (var region in StopRegions)
                    {
                        stopRegionNameList.Add(region.ToString());
                    }
                    var _selectedRegionName = stopRegionNameList[0];
                    _selectedRegion = StopRegions[0];
                    // Default Stop Airport
                    var temp = routes.Where(r => r.StartAirport.Name == _startAirportName && r.StopAirport.GeoRegion == _selectedRegion).ToList();
                    AirportsNameInStopRegion.ClearThenAddRange(temp.Select(r => r.StopAirport.Name).Distinct().ToList());



                    InvokeOnMainThread(() => {
                        pickerView.Hidden = true;
                        btnAirport.Hidden = false;

                        startAirport.SetTitle(args.SelectedTitle, UIControlState.Normal);
                        endRegion.SetTitle(_selectedRegionName, UIControlState.Normal);
                        endAirport.SetTitle(AirportsNameInStopRegion[0], UIControlState.Normal);
                    });
                };

                InvokeOnMainThread(() => {
                    pickerView.Hidden = false;
                    btnAirport.Hidden = true;
                });
            };

            endRegion.TouchUpInside += (object sender, EventArgs e) => {
                SelectedRoutes.ClearThenAddRange(routes.Where(r => r.StartAirport.Name == _startAirportName).ToList());

                StopRegions.ClearThenAddRange(SelectedRoutes.Select(r => r.StopAirport.GeoRegion).Distinct().ToList());

                var stopReionNameList = new List <string>();

                foreach (var region in StopRegions)
                {
                    stopReionNameList.Add(region.ToString());
                }

                CurrentModel              = new RoutePickerViewModel(stopReionNameList);
                pickerView.Model          = CurrentModel;
                CurrentModel.RowSelected += (object picker, RowSelectedEventArgs args) => {
                    _selectedRegion = StopRegions[args.SelectedIndex];

                    var temp = routes.Where(r => r.StartAirport.Name == _startAirportName && r.StopAirport.GeoRegion == _selectedRegion).ToList();

                    AirportsNameInStopRegion.ClearThenAddRange(temp.Select(r => r.StopAirport.Name).Distinct().ToList());

                    if (AirportsNameInStopRegion.Count == 1)
                    {
                        var list = routes.Where(r => r.StartAirport.Name == _startAirportName && r.StopAirport.GeoRegion == _selectedRegion && r.StopAirport.Name == AirportsNameInStopRegion[0]).ToList();

                        if (1 == list.Count)
                        {
                            FinalRoute = list[0];
                        }
                    }

                    // Default Stop Airport
                    InvokeOnMainThread(() => {
                        pickerView.Hidden = true;
                        btnAirport.Hidden = false;

                        endRegion.SetTitle(args.SelectedTitle, UIControlState.Normal);
                        endAirport.SetTitle(AirportsNameInStopRegion[0], UIControlState.Normal);
                    });
                };

                InvokeOnMainThread(() => {
                    pickerView.Hidden = false;
                    btnAirport.Hidden = true;
                });
            };

            endAirport.TouchUpInside += (object sender, EventArgs e) => {
                var temp = routes.Where(r => r.StartAirport.Name == _startAirportName && r.StopAirport.GeoRegion == _selectedRegion).ToList();

                AirportsNameInStopRegion.ClearThenAddRange(temp.Select(r => r.StopAirport.Name).Distinct().ToList());


                CurrentModel              = new RoutePickerViewModel(AirportsNameInStopRegion);
                pickerView.Model          = CurrentModel;
                CurrentModel.RowSelected += (object picker, RowSelectedEventArgs args) => {
                    endAirport.SetTitle(args.SelectedTitle, UIControlState.Normal);

                    var list = routes.Where(r => r.StartAirport.Name == _startAirportName && r.StopAirport.GeoRegion == _selectedRegion && r.StopAirport.Name == args.SelectedTitle).ToList();

                    if (1 == list.Count)
                    {
                        FinalRoute = list[0];
                    }
                };
            };

            btnAirport.TouchUpInside += (object sender, EventArgs e) => {
                if (null != FinalRoute)
                {
                    PerformSegue(NextSegueName, this);
                }
            };
        }