diff options
author | E.Z. Hart <hartez@gmail.com> | 2017-01-25 11:54:54 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-02-17 11:11:46 +0000 |
commit | 2ad9cb93f47f46fcb0584370ab8c297b20912718 (patch) | |
tree | 96868b61a3a9da1fa98ce4bb0d74e7d0c61e76c8 /Xamarin.Forms.Platform.Android/Cells | |
parent | a1c7f9909a16d3253d9afd5cb2e1a839c6fb5a8c (diff) | |
download | xamarin-forms-2ad9cb93f47f46fcb0584370ab8c297b20912718.tar.gz xamarin-forms-2ad9cb93f47f46fcb0584370ab8c297b20912718.tar.bz2 xamarin-forms-2ad9cb93f47f46fcb0584370ab8c297b20912718.zip |
Add localized listener for Android numeric input
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Cells')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs b/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs index e46422a0..bfe8777f 100644 --- a/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs @@ -1,5 +1,7 @@ using System.ComponentModel; using Android.Content; +using Android.Text; +using Android.Text.Method; using Android.Views; namespace Xamarin.Forms.Platform.Android @@ -56,6 +58,14 @@ namespace Xamarin.Forms.Platform.Android UpdateHeight(); } + protected NumberKeyListener GetDigitsKeyListener(InputTypes inputTypes) + { + // Override this in a custom renderer to use a different NumberKeyListener + // or to filter out input types you don't want to allow + // (e.g., inputTypes &= ~InputTypes.NumberFlagSigned to disallow the sign) + return LocalizedDigitsKeyListener.Create(inputTypes); + } + void OnEditingCompleted() { var entryCell = (IEntryCellController)Cell; @@ -88,7 +98,13 @@ namespace Xamarin.Forms.Platform.Android void UpdateKeyboard() { var entryCell = (EntryCell)Cell; - _view.EditText.InputType = entryCell.Keyboard.ToInputType(); + var keyboard = entryCell.Keyboard; + _view.EditText.InputType = keyboard.ToInputType(); + + if (keyboard == Keyboard.Numeric) + { + _view.EditText.KeyListener = GetDigitsKeyListener(_view.EditText.InputType); + } } void UpdateLabel() |