SearchView use multiple comma with numeric keyboard

187 Views Asked by At

I'm trying to get my SearchView to use multiple comma and numbers. Unfortunately I'm stuck with be able to use only one comma using the following settings:

SearchView searchView = (SearchView) menuItem.getActionView();
searchView.setInputType(InputType.TYPE_CLASS_NUMBER + InputType.TYPE_NUMBER_VARIATION_NORMAL);

Another important point is to be able to use the numeric keyboard.

So, basically i would like to write something like 2121,4932,4923 in the following keyboard:

Maybe someone has already faced this problem or can just direct me in a relative question

Thanks in advance, Giacomo.

2

There are 2 best solutions below

2
azizbekian On BEST ANSWER
val searchView: SearchView = search.actionView as SearchView
val editText = searchView.findViewById<EditText>(R.id.search_src_text)
editText.inputType = InputType.TYPE_CLASS_NUMBER + InputType.TYPE_NUMBER_FLAG_DECIMAL
editText.keyListener = DigitsKeyListener.getInstance("0123456789,")

enter image description here

0
Alex Sveshnikov On

I think you'll need to override the OnKeyDown() listener and filter the input there. You may find this link usefull: example code for OnKeyDown() listener