Feuer und Wasser
Feuer und Wasser

Reputation: 27

How to enable suggestions after change inputType in editText?

I want to dinamically change inputType in editText, but after first changing suggestions become disabled. I tried different ways to enable, but nothing helps.

This is my code:

edText.addTextChangedListener(object : TextWatcher {
            override fun afterTextChanged(s: Editable?) {
                val curStart = edText.selectionStart
                val len = listMarkers.first().length

                if (curStart >= len) {
                    val allText = edText.text.toString()
                    val marker = allText.slice(curStart - len until curStart)

                    if (listMarkers.contains(marker)) {
                        edText.inputType = InputType.TYPE_TEXT_FLAG_CAP_WORDS
                    }
                    else {
                        edText.inputType = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
                    }
                    edText.isSingleLine = false
                    edText.imeOptions = EditorInfo.IME_ACTION_NONE
                    edText.setSelection(curStart)
                }
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                // TODO Auto-generated method stub
            }

            override fun beforeTextChanged(
                s: CharSequence?,
                start: Int,
                count: Int,
                after: Int
            ) {
                // TODO Auto-generated method stub
            }
        })

I tried to set different types in block "else". I need to capitalize sentences and enable suggestions.

I even tried to do this:

val type = edText.inputType
edText.inputType = type

But it returns an error.

The same question was already on the site, but I did not find anything useful. How to enable suggestions in an edittext programmatically?

Upvotes: 0

Views: 39

Answers (0)

Related Questions