title: Setting text in EditText with input type number
body: <p>I am using a TextEdit that only accepts numbers as input type and I would like to set the value of the TextEdit when a button is pressed. However, I can't get this to work.</p>
  <p>When I just do textWithAmount.setText(balance), with balance being a long, I get a squiggly line saying that this doesn't conform the setText function and I can't run my code.</p>
  <p>When I cast it to Int (setText(balance.toInt()), I get the following error:</p>
  <blockquote>
  <p>android.content.res.Resources$NotFoundException: String resource ID #0x2710</p>
  </blockquote>
  <p>When I cast it to String (setText(balance.toString()), I get the following error:</p>
  <blockquote>
  <p>java.lang.ClassCastException: android.text.SpannableStringBuilder cannot be cast to java.lang.Long</p>
  </blockquote>
  <p>Kotlin Code:</p>
  <pre><code>val buttonAll = findViewById&lt;Button&gt;(R.id.buttonWithAll)
  var balance : Long = 0
  buttonAll.setOnClickListener{
                  textAmount.setText(balance.toInt())
              }
  </code></pre>
  <p>XML:</p>
  <pre><code>&lt;EditText
          android:id=&quot;@+id/textWithAmount&quot;
          android:layout_width=&quot;228dp&quot;
          android:layout_height=&quot;68dp&quot;
          android:layout_marginStart=&quot;16dp&quot;
          android:layout_marginTop=&quot;10dp&quot;
          android:ems=&quot;100&quot;
          android:importantForAutofill=&quot;no&quot;
          android:inputType=&quot;number&quot;
          app:layout_constraintEnd_toStartOf=&quot;@+id/buttonWithAll&quot;
          app:layout_constraintHorizontal_bias=&quot;0.5&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/textView4&quot; /&gt;
  
      &lt;Button
          android:id=&quot;@+id/buttonWithAll&quot;
          android:layout_width=&quot;68dp&quot;
          android:layout_height=&quot;68dp&quot;
          android:layout_marginEnd=&quot;9dp&quot;
          android:text=&quot;@string/all&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintHorizontal_bias=&quot;0.5&quot;
          app:layout_constraintStart_toEndOf=&quot;@+id/textWithAmount&quot;
          app:layout_constraintTop_toTopOf=&quot;@+id/textWithAmount&quot; /&gt;
  </code></pre>
  <p>Does anyone know a solution to this? Any answers would be appreciated</p>
  <p>Edit:
  I just realized I also have a textChangedListener on the same TextEdit which is probably called when I fill it. Maybe something is wrong there:</p>
  <pre><code>textAmount.addTextChangedListener { text -&gt;
                      val input : Long = text as Long
                      if(input &gt; cash){
                          textAmount.setText(cash.toString())
                      }
                  }```
  </code></pre>