title: Android data binding converter for signed ints
body: <p>I've been trying to figure out how to create a DataBindingConverter to allow two-way databinding for edittext fields that may contain signed ints. Currently, my converter functions look like this.</p>
  <pre><code>@InverseMethod(&quot;convertStringToInt&quot;)
  fun convertIntToString(value: Int?): String {
      return value?.toString() ?: &quot;&quot;
  }
  
  fun convertStringToInt(value: String): Int? {
      if (TextUtils.isEmpty(value) || !value.matches(Regex(&quot;-?\\d*&quot;))) {
          return null
      }
      return value.toIntOrNull()
  }
  </code></pre>
  <p>While this <em>technically</em> allows for negative values, trying to type in a negative number naturally by starting with the &quot;-&quot; sign obviously fails since &quot;-&quot; isn't an int and thus defaults to null and sets the edittext to empty string. Right now I'm sidestepping the problem by just binding edittext fields that may contain negative numbers as strings and parsing them out when needed in the view model, but I'd like to figure out if there's a cleaner solution out there.</p>