sushant_kaura
sushant_kaura

Reputation: 13

EditText not accepting negative numbers

I have an android application which has four EditText and these 4 EditTExt accepts negative values. My application also has a calculate button to add these four values and show result in TextView and a clear button which clears the four EditText values.

When I click on calculate button and then reset button. I am not able to enter negative vales to 4 EditText. EditText accepts "-"(negative sign) but nothing after that.

XML of EditText

 <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" />

onClick Reset button

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();

As you can see, I have tried 3 different options to rest the value but still EditText does not accept any value after "-".

Help will be appriciated :)

Upvotes: 1

Views: 1237

Answers (1)

CodeWalker
CodeWalker

Reputation: 2368

Try this - edit_text.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);

Upvotes: 1

Related Questions