【问题标题】:EditText not accepting negative numbersEditText 不接受负数
【发布时间】:2014-12-16 19:55:04
【问题描述】:

我有一个 android 应用程序,它有四个 EditText,这四个 EditTExt 接受负值。我的应用程序还有一个计算按钮,用于添加这四个值并在 TextView 中显示结果,还有一个清除按钮,用于清除四个 EditText 值。

当我点击计算按钮然后重置按钮时。我无法在 4 EditText 中输入负值。 EditText 接受“-”(负号),但之后不接受。

EditText 的 XML

 <EditText
  android:layout_width="105dp"
  android:layout_height="25dp"
  android:inputType="numberSigned|numberDecimal"
  android:id="@+id/editText_L1Angle"
  android:textColor="#FFFFFF"
  android:paddingLeft="40dp"
  android:paddingRight="10dp" />

点击重置按钮

tempL1Angle = (EditText) findViewById(R.id.editText_L1Angle);
            tempL2Angle = (EditText) findViewById(R.id.editText_L2Angle);
            tempL3Angle = (EditText) findViewById(R.id.editText_L3Angle);
            tempL4Angle = (EditText) findViewById(R.id.editText_L4Angle);

            //tempL1Angle.setText("0");
            //tempL2Angle.setText("0");
            //tempL3Angle.setText("0");
            //tempL4Angle.setText("0");

            tempL1Angle.setText("");
            tempL2Angle.setText("");
            tempL3Angle.setText("");
            tempL4Angle.setText("");

            //tempL1Angle.getText().clear();
            //tempL2Angle.getText().clear();
            //tempL3Angle.getText().clear();
            //tempL4Angle.getText().clear();

如您所见,我尝试了 3 种不同的选项来保留值,但 EditText 仍然不接受“-”之后的任何值。

将获得帮助:)

【问题讨论】:

    标签: android android-edittext


    【解决方案1】:

    试试这个 - edit_text.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);

    【讨论】:

      猜你喜欢
      • 2015-08-13
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多