MAUI Autocomplete Completed Event Not Fired On Item Selected - Leaves Keyboard Open

1 Answer 236 Views
AutoComplete
billy
Top achievements
Rank 2
Iron
Iron
Iron
billy asked on 21 Jun 2023, 09:46 PM

I have implemented the AutoComplete feature fed from API successfully. But when an Item in the list is selected, it leaves the Keyboard open.

The keyboard will only close upon hitting the "return" key in the soft keyboard. Users (in almost all cases) will expect the keyboard to close when selecting an item as it closes the dropdown list when item is selected.

How can I close the keyboard when the autocomplete item is selected? There doesn't appear to be an ItemSelected event.

1 Answer, 1 is accepted

Sort by
1
Accepted
Didi
Telerik team
answered on 22 Jun 2023, 12:40 PM

Hello Billy,

The AutoComplete drop down closes when item is selected. Regarding to the keyboard the behavior happens also with MAUI Entry control. When calling Unfocus() on Maui Entry the entry gets Unfocus but the keyboard remains open, same behavior with AuoComplete.

As a solution on Android you can use the following approach:

<telerik:RadAutoComplete x:Name="auto"
                                 SuggestionItemSelected="auto_SuggestionItemSelected"/>
    private void auto_SuggestionItemSelected(object sender, Telerik.Maui.Controls.AutoComplete.SuggestionItemSelectedEventArgs e)
    {
#if ANDROID
        var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
        HideSoftInput(activity);
#endif
    }

#if ANDROID
    public static void HideSoftInput(Activity activity)
    {
        try
        {
            if (activity == null || activity.IsFinishing)
            {
                return;
            }

            Android.Views.Window window = activity.Window;
            if (window == null)
            {
                return;
            }

            Android.Views.View view = window.CurrentFocus;

            if (view == null)
            {
                view = window.DecorView;
            }



            if (view == null)
            {
                return;
            }

            InputMethodManager imm = (InputMethodManager)(activity.ApplicationContext.GetSystemService(Android.Content.Context.InputMethodService));

            if (imm == null || !imm.IsActive)
            {
                return;
            }

            imm.HideSoftInputFromWindow(view.WindowToken, HideSoftInputFlags.None);
        }
        catch (System.Exception e)
        {

        }
    }
#endif

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
AutoComplete
Asked by
billy
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Didi
Telerik team
Share this question
or