Bug 25373

Summary: [Android] Numeric keyboard does not allow to enter negative values in Entry
Product: Forms Reporter: Prashant Cholachagudda <prchol>
Component: FormsAssignee: Bugzilla <bugzilla>
Status: RESOLVED ANSWERED    
Severity: normal CC: eric.maupin, jas, paul.dipietro, sadika, seth.rosetter, tomasz.bitowt
Priority: Normal    
Version: 1.2.3   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: AC Is this bug a regression?: ---
Last known good build:

Description Prashant Cholachagudda 2014-12-15 01:31:21 UTC
In Xamarin.Forms for Android, Numeric Keyboard does not accept negative values (e.g -123) in both v1.2.3 and v1.3

Sample code:

	public class App
	{
		public static Page GetMainPage ()
		{	
			return new ContentPage { 
				Content = new Entry {
					VerticalOptions = LayoutOptions.CenterAndExpand,
					HorizontalOptions = LayoutOptions.CenterAndExpand,
					Keyboard = Keyboard.Numeric,

				},
			};
		}
	}
Comment 2 Sadik Ali 2014-12-15 06:52:19 UTC
I have checked this issue and able to reproduce. To reproduce this issue I have followed the steps mentioned below:

1. Create Xamarin Forms  Blank.App(Xamarin.forms portable) application in XS.  
2. Open App.cs file and add the following code:
       return new ContentPage { 
				    Content = new Entry {
					WidthRequest=160,
					HeightRequest=50,
					VerticalOptions = LayoutOptions.CenterAndExpand,
					HorizontalOptions = LayoutOptions.CenterAndExpand,
					Keyboard = Keyboard.Numeric,
                                  }
                                };
3. Deploy it on emulator, it deploy successfully.
4. Try to write negative values (e.g -123).
5. Observed that user is not able to enter negative values.

Screencast: http://www.screencast.com/t/fAYUH6Tn6

Environment info: 

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: 8.4.0.47 (Business Edition)
Hash: 7244769
Branch: 
Build date: 2014-12-11 14:54:30-0500

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 3 Tomasz Bitowt 2015-05-14 04:41:55 UTC
We have found solution for this problem.

You have to create your own control for NumericEntry like:

	public class NumericTextBox : TextBox
	{
		public NumericTextBox()
		{
			this.Keyboard = Keyboard.Numeric;
		}
	}

Then, in Android project, create Custom Renderer:

	[assembly: ExportRenderer(typeof(NumericTextBox), typeof(CustomNumericTextboxRenderer))]

	namespace xxx.Droid.Renderers
	{
		public class CustomNumericTextboxRenderer : EntryRenderer
		{
			protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
			{
				base.OnElementChanged(e);

				var native = Control as EditText;

				native.InputType = Android.Text.InputTypes.ClassNumber | Android.Text.InputTypes.NumberFlagSigned | Android.Text.InputTypes.NumberFlagDecimal;
			}
		}
	}

This has been tested and working for Droid devices. It allows to enter negative/positive values with decimal point. It properly forbirs entering wrong decimal value.
Comment 4 Paul DiPietro [MSFT] 2016-04-05 15:44:45 UTC
Not allowing use of the negative in the numeric entry is default Android behavior. As indicated above, a custom renderer can enable the behavior.