Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何确保Android 7中的java.text.DecimalFormat.parse(String text,ParsePosition pos)方法行为与以前的版本类似?_Java_Android_Android 7.0 Nougat_Decimalformat - Fatal编程技术网

如何确保Android 7中的java.text.DecimalFormat.parse(String text,ParsePosition pos)方法行为与以前的版本类似?

如何确保Android 7中的java.text.DecimalFormat.parse(String text,ParsePosition pos)方法行为与以前的版本类似?,java,android,android-7.0-nougat,decimalformat,Java,Android,Android 7.0 Nougat,Decimalformat,与以前的版本相比,Android 7中的java.text.DecimalFormat.parse(字符串文本,ParsePosition pos)的行为有所不同 在android7中,对于输入字符串“12345”(数字之间有空格),它返回值为12345的“java.lang.Number”,其中与android7之前的版本一样,它返回null 我想确认输入“12345”是无效输入。因此,出于我的目的,如果输入是“12345”,我希望总是返回null(因为数字不应该有空格)。当我在Android

与以前的版本相比,Android 7中的java.text.DecimalFormat.parse(字符串文本,ParsePosition pos)的行为有所不同

在android7中,对于输入字符串“12345”(数字之间有空格),它返回值为12345的“java.lang.Number”,其中与android7之前的版本一样,它返回null

我想确认输入“12345”是无效输入。因此,出于我的目的,如果输入是“12345”,我希望总是返回null(因为数字不应该有空格)。当我在Android 7中调试时,DecimalFormat类本质上使用的是Android.icu.text,但当我在以前的版本中调试时,DecimalFormat类使用的是libcore.icu.NativeDecimalFormat。
下一页讨论从java.text.DecimalFormat到anroid.icu.text.DecimalFormat的迁移。


如何确保在所有设备中使用libcore.icu.NaticeDecimalFormat

我怀疑是否有可能在Android 7.0+中使用libcore.icu.NativeDecimalFormat。我不会假设这个类会继续存在。使用不同的验证方法(例如regex),因为在某些语言(地区)中空格被用作千位分隔符,所以解析器非常宽松。如果您不想支持千个分隔符和特定于区域设置的格式,那么应该使用类似于
Integer.parseInt(String)
(或
Long
Double
变体)或
new bigdecimic(String)的内容Double.parseDouble正在为我工作,但是它没有一个重载的方法,它把区域设置作为参数(对于我的需求来说,它是考虑区域设置的必要条件)。