1

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.

azizbekian
  • 58,054
  • 12
  • 164
  • 238
G. Ciardini
  • 1,109
  • 1
  • 15
  • 28

2 Answers2

1
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

azizbekian
  • 58,054
  • 12
  • 164
  • 238
  • That's perfect, i've adapted your code to java and it's working fine! Thanks <3 – G. Ciardini Mar 09 '20 at 09:38
  • Unfortunately i've found a case that this isn't working if you want to check it out https://stackoverflow.com/questions/61212695/setkeylistener-will-override-setinputtype-and-change-the-keyboard – G. Ciardini Apr 14 '20 at 16:36
0

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

Alex Sveshnikov
  • 3,890
  • 1
  • 7
  • 25