title: Android Kotlin: onTextChanged not being triggered for EditText
body: <p>I am creating an <code>EditText</code> box with line numbers on the side. To achieve this, I have code in the <code>onTextChanged</code> method of the <code>addTextChangedListener</code> that updates the line numbers for the <code>EditText</code>. For some reason however, the <code>onTextChanged</code> event never seems to fire when I type in the <code>EditText</code>, as the <code>println</code> statement is not being activated.</p>
  
  <p>Below is my XML code:</p>
  
  <pre><code>&lt;GridLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:rowCount="1"
      android:columnCount="2"&gt;
  
      &lt;TextView
          android:id="@+id/linenumber"
          android:layout_width="30dp"
          android:layout_height="200dp"
          android:layout_row="0"
          android:layout_column="0"
          android:layout_columnSpan="1"
          android:layout_alignParentStart="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_alignParentBottom="true"
          android:background="@drawable/border_style"
          android:gravity="center_horizontal"
          android:text="1"
          android:textSize="18dp"&gt;&lt;/TextView&gt;
  
      &lt;EditText
          android:id="@+id/textbox"
          android:layout_width="0dp"
          android:layout_height="200dp"
          android:layout_row="0"
          android:layout_column="1"
          android:layout_columnSpan="1"
          android:layout_columnWeight="1"
          android:ems="5"
          android:gravity="left|top"
          android:inputType="textMultiLine"
          android:padding="10dp"
          android:text="" /&gt;
  &lt;/GridLayout&gt;
  </code></pre>
  
  <p>Below is my Kotlin code:</p>
  
  <pre><code>var textbox1: EditText = findViewById(R.id.textbox);
  var lineNumber: TextView = findViewById(R.id.linenumber);
  
  // Add the line numbers or remove the line numbers based on the user's input
  textbox1.addTextChangedListener(object : TextWatcher {
      override fun afterTextChanged(p0: Editable?) {
      }
  
      override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
      }
  
      override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
          // Retrieve the number of lines in the user's input
          var lines:Int = lineNumber.getLineCount()
          var linesText:String = "";
  
          // Loop through the lines
          for (i in 1..lines) {
              linesText = linesText + "\n" + i;
          }
  
          println("linesText = " + linesText)
          // Update the line numbers
          lineNumber.setText(linesText);
      }
  })
  </code></pre>