title: How to control input in EditText in Android?
body: <p>This is a two part question:</p>
  
  <p>1) I'm currently using</p>
  
  <pre><code>android:inputType="numberDecimal|numberSigned"
  </code></pre>
  
  <p>to control the input in my app.</p>
  
  <p>However, I keep getting crash reports from users with NumberFormatExceptions.
  One of them was:</p>
  
  <pre><code>Caused by: java.lang.NumberFormatException: Invalid float: "2,7"
  </code></pre>
  
  <p>So clearly users are somehow circumventing my measures to control the input and using "," instead of ".". I've temporarily used</p>
  
  <pre><code>String.replace(",", ".")
  </code></pre>
  
  <p>in an attempt to fix it but I still get NumberFormatExceptions .</p>
  
  <p>What do I do?</p>
  
  <p>2) How do I force the soft keyboard app to display only a number pad, "-" and "."?</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;EditText
          android:id="@+id/speed"
          android:layout_width="0px"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:inputType="number|numberDecimal" &gt;
  </code></pre>
  
  <p>In Activity:</p>
  
  <pre><code>public void onClickCalc(View view)
  {
      switch(view.getId())
      {
                String sp = speed.getText().toString().replace(",", ".");
                  if(functions.isNotValid(sp))
                  {
                      Toast.makeText(this, "Invalid input.", Toast.LENGTH_LONG).show();
                      return;
                  }
  
                  float speed = Float.parseFloat(sp);
  
  ... logic here
  }
  </code></pre>
  
  <p>In the class functions:</p>
  
  <pre><code>public static boolean isNotValid(String editable)
  {
      try
      {
          float x = Float.parseFloat(editable);
      }
      catch(NumberFormatException nFE)
      {
          return true;
      }
  
      return false;
  }
  </code></pre>