splitwise / TokenAutoComplete

Gmail style MultiAutoCompleteTextView for Android
Apache License 2.0
1.3k stars 383 forks source link

comma on on screen keyboard makes item disappear #443

Closed phazei closed 1 year ago

phazei commented 1 year ago

I have a super simple implementation:

class StopTokenCompleteTextView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : TokenCompleteTextView<String>(context, attrs) {

    override fun defaultObject(completionText: String): String {
        return completionText.trim()
    }

    override fun getViewForObject(token: String): View {
        val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val view = layoutInflater.inflate(R.layout.token_layout, parent as ViewGroup, false)
        (view.findViewById<View>(R.id.token_text) as TextView).text = token
        return view
    }
}

In android studio emulator, it works fine when I use my full keyboard. Type something, hit comma or enter, it's a tag. But with the on screen keyboard, when I type something and press comma, it disappears. If I type "aaaaa ," or "aaaaa.," it works (there's a space or period before the comma in those), but "aaaaa," and it disappears. Same happens with the semicolon.

I'm using 3.0.2.

edit: Actually, comma or semicolon work fine as long as it isn't all letters.... maybe there's some default filtering happening? When it disappears, both the added, then removed callback are called.

It seems when the normal keyboard is used, inside of setFilters, the source is simply "," but if the soft keyboard is used, the source is "aaaa," It also seems like "beforeTextChange" is called more times when it's the soft keyboard.

Final edit: Updated to 4.0.0-beta5, works, whew

phazei commented 1 year ago

Thought I'd also note that it eat the tab key, so if I'm tabbing through the fields, it gets stuck there. I fix it like so:

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
    when (keyCode) {
        KeyEvent.KEYCODE_TAB -> {
            return false
        }
    }
    return super.onKeyDown(keyCode, event)
}