title: doAfterTextChanged{} kotlin
body: <p>I'm trying to write an application in which the user can write a text, and control its text size by typing the size he wants in an Edittext field in a fragment container and the text he wrote at first in an Edittext should change its size immediately
  I keep getting a null issue, the text in the main edittext isn't' passed.
  how to implement &quot;doAfterTextChanged{}&quot; correctly?</p>
  <p>here is my code in the fragment:</p>
  <pre><code>class font_fragment : Fragment() {
  // TODO: Rename and change types of parameters
  //lateinit var editText: EditText
  lateinit var textSize: EditText
  
  private var param1: String? = null
  private var param2: String? = null
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      arguments?.let {
          param1 = it.getString(ARG_PARAM1)
          param2 = it.getString(ARG_PARAM2)
      }
  }
  
  override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?,
      savedInstanceState: Bundle?
  ): View? {
      //Inflate the layout for this fragment
      val v = inflater.inflate(R.layout.fragment_font_fragment, container, false)
      //editText = v.findViewById(R.id.editText)
  
      textSize = v.findViewById(R.id.textSize)
    
  
      textSize.doAfterTextChanged {
         v.findViewById&lt;EditText&gt;(R.id.editText)?.setTextSize(textSize.text.toString().toFloat())
      }
  
      return v
  }
  }
  </code></pre>
  <p>and this is my main XML ( containing the EditText):</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;LinearLayout
          android:id=&quot;@+id/linearLayout&quot;
          android:layout_width=&quot;394dp&quot;
          android:layout_height=&quot;96dp&quot;
          android:layout_marginTop=&quot;16dp&quot;
          android:background=&quot;@drawable/red_boarded_back&quot;
          android:orientation=&quot;horizontal&quot;
          android:layout_marginRight=&quot;10dp&quot;
          android:layout_marginLeft=&quot;10dp&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintHorizontal_bias=&quot;0.47&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; &gt;
      &lt;/LinearLayout&gt;
  
      &lt;EditText
          android:id=&quot;@+id/editText&quot;
          android:layout_width=&quot;385dp&quot;
          android:layout_height=&quot;410dp&quot;
          android:layout_marginTop=&quot;15dp&quot;
          android:layout_marginRight=&quot;10dp&quot;
          android:layout_marginLeft=&quot;10dp&quot;
          android:background=&quot;@drawable/blue_boarder_back&quot;
          android:ems=&quot;10&quot;
          android:text=&quot;test&quot;
          android:gravity=&quot;top&quot;
          android:hint=&quot;Write your text here..&quot;
          android:inputType=&quot;textPersonName&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/linearLayout&quot;
          android:layout_marginBottom=&quot;20dp&quot;/&gt;
  
      &lt;Button
          android:id=&quot;@+id/button3&quot;
          android:layout_width=&quot;176dp&quot;
          android:layout_height=&quot;61dp&quot;
          android:layout_marginStart=&quot;16dp&quot;
          android:text=&quot;save&quot;
          android:layout_marginTop=&quot;10dp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/editText&quot;
          app:layout_constraintVertical_bias=&quot;0.333&quot;
          android:layout_marginBottom=&quot;20dp&quot;/&gt;
  
      &lt;Button
          android:id=&quot;@+id/button4&quot;
          android:layout_width=&quot;176dp&quot;
          android:layout_height=&quot;61dp&quot;
          android:text=&quot;open&quot;
          android:layout_marginTop=&quot;10dp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintHorizontal_bias=&quot;0.627&quot;
          app:layout_constraintStart_toEndOf=&quot;@+id/button3&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/editText&quot;
          app:layout_constraintVertical_bias=&quot;0.333&quot;
          android:layout_marginBottom=&quot;20dp&quot;/&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>and the fragments XML (containing the textSize):</p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;96dp&quot;
      tools:context=&quot;.font_fragment&quot;&gt;
  
      &lt;!-- TODO: Update blank fragment layout --&gt;
  
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:orientation=&quot;horizontal&quot;
          android:gravity=&quot;center&quot;&gt;
  
          &lt;EditText
              android:id=&quot;@+id/textSize&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_weight=&quot;1&quot;
              android:ems=&quot;6&quot;
              android:layout_marginLeft=&quot;10dp&quot;
              android:inputType=&quot;textPersonName&quot;
              android:hint=&quot;Enter text size&quot; /&gt;
  
          &lt;TextView
              android:id=&quot;@+id/textView&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_weight=&quot;1&quot;
              android:text=&quot;Font Style&quot;
              android:layout_marginLeft=&quot;10dp&quot;/&gt;
  
          &lt;CheckBox
              android:id=&quot;@+id/Bold&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_weight=&quot;1&quot;
              android:text=&quot;Bold&quot; /&gt;
  
          &lt;CheckBox
              android:id=&quot;@+id/Italic&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_weight=&quot;1&quot;
              android:text=&quot;Italic&quot; /&gt;
      &lt;/LinearLayout&gt;
  &lt;/FrameLayout&gt;
  </code></pre>