I want to reset an edit text. I have tried getText().clear() but hint does not appear. Set to "" is not my goal because the listener triggers again. My goal is only to have display hint again. How to ?
FINAL EDIT question: the final goal is to replace a character by another character so I thinked about using hint. But in fact, there is a better solution. See my answer below, or a more beautifull solution with Sinner of the System's answer.
OLD EDIT 1 :
override fun afterTextChanged(p0: Editable?) {
var hintSave:String=PKd.text.toString().replace(".","+")
if (!PKd.text.isNullOrEmpty()){
Handler().postDelayed({
PKf.setText("Pkf")
PKd.setText("")
PKd.hint=hintSave
}, 3000)}
}
OLD EDIT 2 :
The hint don't appear in one way what is a problem. Can we delay the input into to take account input only one time ?
same as your answer but more kotlin styled
val Pkd = findViewById<EditText>(R.id.editTexT_PKd)
val regex = Regex("[.,]")
Pkd.doAfterTextChanged {
if (it?.contains(regex) == true) {
Pkd.setText(it.replace(regex, "+"))
Pkd.setSelection(it.length)
}
}