Exemple #1
0
        //https://philio.me/styling-the-searchview-with-appcompat-v21/
        //https://code.google.com/p/android/issues/detail?id=70754
        public void Init(string searchIdName, string textFieldHint, bool topLine, bool serachLine, bool bottomline = false)
        {
            _stoppingPlaceViewModel = Stops.Setup.IoC.Container.Get <Core.ViewModels.SearchViewModel> ();


            /*
             * Load last selected on startup
             */
            _searchView           = _view.FindViewById <Android.Support.V7.Widget.SearchView> (Resource.Id.SearchFragmentSearch);
            _searchView.QueryHint = textFieldHint;
            _searchView.SetOnQueryTextListener(this);
            _searchView.SetOnSuggestionListener(this);

            ((EditText)_searchView.FindViewById(Resource.Id.search_src_text)).CustomSelectionActionModeCallback
                = this;

            if (mSuggestionsAdapter == null)
            {
                MatrixCursor cursor = new MatrixCursor(COLUMNS);
                mSuggestionsAdapter = new SuggestionsAdapter(Android.App.Application.Context, cursor);
            }

            _searchView.SuggestionsAdapter = mSuggestionsAdapter;


            if (!topLine)
            {
                var topLineView = _view.FindViewById <FrameLayout> (Resource.Id.SearchFragmentTopLine);
                topLineView.Visibility = topLine ? ViewStates.Visible : ViewStates.Gone;
            }

            if (!serachLine)
            {
                var view = _view.FindViewById <FrameLayout> (Resource.Id.SearchFragmentDragLine);
                view.Visibility = serachLine ? ViewStates.Visible : ViewStates.Gone;
            }
            if (!bottomline)
            {
                var view = _view.FindViewById <FrameLayout>(Resource.Id.SearchFragmentBottomLine);
                view.Visibility = serachLine ? ViewStates.Visible : ViewStates.Gone;
            }

            int searchEditTextId = Resource.Id.search_src_text;             // for AppCompat

            // get AutoCompleteTextView from SearchView
            AutoCompleteTextView searchEditText = (AutoCompleteTextView)_searchView.FindViewById(searchEditTextId);
            View dropDownAnchor = _searchView.FindViewById(searchEditText.DropDownAnchor);

            dropDownAnchor.AddOnLayoutChangeListener(this);

            searchEditText.LongClick += (object sender, View.LongClickEventArgs e) => {
                SetChoicedStop(null);
            };

            /*
             * Init the view model and set the last chocied stop
             */
            _stoppingPlaceViewModel.Init(searchIdName);
            if (_stoppingPlaceViewModel.HasLatestCLickeStop())
            {
                _choicedStop = _stoppingPlaceViewModel.GetLatestCLickeStop();
                _ignoreAutoCompleteTextChange = true;

                _searchView.SetQuery(_choicedStop.Name, true);
                Events.Trigger("initWithStop", _choicedStop, 100);
            }

            var btnPos = _view.FindViewById <ImageButton> (Resource.Id.btnPos);

            btnPos.Click += (object sender, EventArgs e) => {
                Events.Trigger("locationClick", null);
                return;
            };
        }