示例#1
0
        private void CreateLayout()
        {
            // Vertical stack layout.
            LinearLayout layout = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical
            };

            // Search bar.
            _mySearchBox = new AutoCompleteTextView(this)
            {
                Text = "Coffee"
            };
            layout.AddView(_mySearchBox);

            // Location search bar.
            _myLocationBox = new AutoCompleteTextView(this)
            {
                Text = "Current Location"
            };
            layout.AddView(_myLocationBox);

            // Disable multi-line searches.
            _mySearchBox.SetMaxLines(1);
            _myLocationBox.SetMaxLines(1);

            // Search buttons; horizontal layout.
            LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                ViewGroup.LayoutParams.MatchParent,
                1.0f
                );
            LinearLayout searchButtonLayout = new LinearLayout(this)
            {
                Orientation = Orientation.Horizontal
            };

            _mySearchButton = new Button(this)
            {
                Text = "Search All", LayoutParameters = param
            };
            _mySearchRestrictedButton = new Button(this)
            {
                Text = "Search View", LayoutParameters = param
            };

            // Add the buttons to the layout.
            searchButtonLayout.AddView(_mySearchButton);
            searchButtonLayout.AddView(_mySearchRestrictedButton);

            // Progress bar.
            _myProgressBar = new ProgressBar(this)
            {
                Indeterminate = true, Visibility = Android.Views.ViewStates.Gone
            };
            layout.AddView(_myProgressBar);

            // Add the layout to the view.
            layout.AddView(searchButtonLayout);

            // Add the mapview to the view.
            _myMapView = new MapView(this);
            layout.AddView(_myMapView);

            // Show the layout in the app.
            SetContentView(layout);

            // Disable the buttons and search bar until the geocoder is ready.
            _mySearchBox.Enabled              = false;
            _myLocationBox.Enabled            = false;
            _mySearchButton.Enabled           = false;
            _mySearchRestrictedButton.Enabled = false;

            // Hook up the UI event handlers for suggestion & search.
            _mySearchBox.TextChanged        += _mySearchBox_TextChanged;
            _myLocationBox.TextChanged      += _myLocationBox_TextChanged;
            _mySearchButton.Click           += _mySearchButton_Click;
            _mySearchRestrictedButton.Click += _mySearchRestrictedButton_Click;
        }