Last active
April 11, 2019 16:37
-
-
Save felipeslongo/a333878f0a589a9baf5fda061f9f0dba to your computer and use it in GitHub Desktop.
Extension method ShowSuggestions to AutoCompleteTextView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.Widget; | |
namespace App.Droid.Extensions | |
{ | |
/// <summary> | |
/// Extension method ShowSuggestions to AutoCompleteTextView | |
/// </summary> | |
/// <seealso cref="https://stackoverflow.com/questions/2126717/android-autocompletetextview-show-suggestions-when-no-text-entered"/> | |
public static class AutoCompleteTextView_ShowSuggestions | |
{ | |
public static void ShowSuggestionsOnInteraction(this AutoCompleteTextView @this) | |
{ | |
@this.ShowSuggestionsOnFocus(); | |
@this.ShowSuggestionsOnClick(); | |
@this.ShowSuggestionsOnEmptyText(); | |
} | |
/// <summary> | |
/// Configure the FocusChange EventHandler to show the drop down suggestions on focus. | |
/// </summary> | |
/// <param name="this"></param> | |
public static void ShowSuggestionsOnFocus(this AutoCompleteTextView @this) | |
{ | |
@this.FocusChange += (sender, args) => | |
{ | |
if(args.HasFocus) | |
@this.ShowDropDown(); | |
}; | |
} | |
public static void ShowSuggestionsOnClick(this AutoCompleteTextView @this) | |
=> @this.Click += (sender, args) => @this.ShowDropDown(); | |
public static void ShowSuggestionsOnEmptyText(this AutoCompleteTextView @this) | |
{ | |
@this.TextChanged += async (sender, args) => | |
{ | |
if (!string.IsNullOrEmpty(@this.Text)) | |
return; | |
await Task.Delay(TimeSpan.FromMilliseconds(300)); | |
@this.ShowDropDown(); | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment