In my application I have popup window with EditText field. If there is more one dot I want to invalidate positive button, mean to make it greyed out and unable to click. I looked on Java code and tried few solutions but I didn't figure out how to make it work. My code:
fun dialogBuilder(){
var dots = 0
lateinit var inputText: String
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.moneyStatus))
val input = EditText(this)
input.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED
input.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
input.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int,
count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int,
before: Int, count: Int) {
val length = s.length
if (length > 0){
for (i in 0..length){
if (i < length) {
if (s[i] == '.') {
dots += 1
}
}
}
}
}
})
builder.setView(input)
builder.setPositiveButton("OK") {
dialog, which -> inputText = input.text.toString()
money.setText(inputText)
}
builder.setNegativeButton(getString(R.string.cancel)) {
dialog, which -> dialog.cancel()
}
if (dots > 1){
//gray out "OK" button
}
builder.show()
}
}