Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i add an on "addTextChangedListener(textWacther)" on my editText and i try to run the app and when entering something in that field it just close the app, and isn't my way of enabling the button back correct?

Java
class MainActivity : AppCompatActivity() {
lateinit var num1TextE: EditText
lateinit var resultText: TextView
lateinit var plusBtn: Button


override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    num1TextE = findViewById(R.id.firstNum_TextE)
    plusBtn = findViewById(R.id.plus_btn)
    resultText = findViewById(R.id.result_TextV)
    resultText.visibility = View.GONE

    plusBtn.isClickable= false
    plusBtn.isEnabled = false
    num1TextE.addTextChangedListener(textWatcher)




    plusBtn.setOnClickListener {
        var num1 = num1TextE.text.toString().toInt()
        var num2 = num2TextE.text.toString().toInt()
        resultText.visibility = View.VISIBLE
        resultText.text = "Result is ${num1 + num2}"

   }
}

var textWatcher = object : TextWatcher {
    override fun afterTextChanged(p0: Editable?) {

    }

    override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
        var test: String = num1TextE.text.toString()
        if(! test.isEmpty()) {
            plusBtn.isClickable = true
            plusBtn.isEnabled = true
        }
       }
    }
}



Log

 2019-07-31 17:02:01.633 3078-3078/com.example.mycalculator E/InputEventSender: Exception dispatching finished signal.
2019-07-31 17:02:01.633 3078-3078/com.example.mycalculator E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
2019-07-31 17:02:01.637 3078-3078/com.example.mycalculator E/MessageQueue-JNI: kotlin.NotImplementedError: An operation is not implemented: not implemented
       at com.example.mycalculator.MainActivity$textWatcher$1.beforeTextChanged(MainActivity.kt:101)


What I have tried:

i tried many things, but nothing worked.
Posted
Updated 31-Jul-19 8:24am

1 solution

Quote:
at com.example.mycalculator.MainActivity$textWatcher$1.beforeTextChanged(MainActivity.kt:101)
Quote:
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
Either add an implementation to that method, or remove the TODO call and leave the method blank.
 
Share this answer
 
Comments
hiwa doski 31-Jul-19 14:33pm    
Thanks, that worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900