0

I am new to Android Development, so my problem is whenever I try to use addTextChangedListener method inside the fragment.kt file for my EditText widget and try to type a letter in it then the parent activity crashes instantly and the previous activity gets open. Also, it is not showing any error. When I comment that method , the app works perfectly.

Here is my code of fragment file

class FavoriteFragment : Fragment() {

    lateinit var etTest : EditText

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        val view = inflater.inflate(R.layout.fragment_favorite, container, false)

        etTest = view.findViewById(R.id.etTest)

        etTest.setOnClickListener{
            Toast.makeText(context, "You Touched" , Toast.LENGTH_SHORT).show()
        }



        try{//This Method is not working

             etTest.addTextChangedListener(object : TextWatcher {

                 override fun afterTextChanged(s: Editable?) {
                     var str = s.toString()
                     Toast.makeText(context, str , Toast.LENGTH_SHORT).show()
                 }

                 override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
                     TODO("Not yet implemented")
                 }

                 override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
                     TODO("Not yet implemented")
                 }

             })
        }catch ( e: Exception)
        {
            e.printStackTrace()
        }



        return view
    }


}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • 1
    Remove the `TODO`s. Those throw `NotImplementedError`s at runtime. You might also have a look at [this post](https://stackoverflow.com/q/23353173) to see how to track down the specific issue when you get a crash. – Mike M. Sep 29 '21 at 18:10
  • 1
    Thanks a lot! It is working now. – Abhinav Mohan Mishra Sep 29 '21 at 18:16

0 Answers0