简体   繁体   English

Android模拟器:插入负数?

[英]Android emulator : insert negative number?

I suppose it must be easy but how do I insert a negative number in an EditText ? 我想它一定很容易,但如何在EditText插入负数?

I am running the emulator on a Mac. 我正在Mac上运行模拟器。

Thank you. 谢谢。

Just press '-' before you enter the number? 在输入数字之前,只需按' - '即可?

If that's not possible, there is probably something wrong with the inputType of the editText. 如果那是不可能的,editText的inputType可能有问题。 For example, android:inputType="numberDecimal" doesn't allow negative numbers. 例如, android:inputType="numberDecimal"不允许负数。 In that case you should add: android:inputType="numberDecimal|numberSigned" . 在这种情况下,你应该添加: android:inputType="numberDecimal|numberSigned"

In resource file .axml, EditBox change type 在资源文件.axml中,EditBox更改类型

android:inputType="numberDecimal"

to

android:inputType="numberDecimal|numberSigned"

It works for me 这个对我有用

EditText yourEditText = (EditText)findViewById(R.id.yourEditText);
yourEditText.setText("whatever");
editText.setText(String.valueOf(-1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM