4

I don't manage to set the numeric input type to the SearchView in my ActionBar. I have the following searchable.xml file in my res/xml folder:

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:inputType="number"
    android:label="@string/app_name"
    android:hint="@string/search_hint">
</searchable>  

And I set the searchable configuration to the SearchView as follows:

 // Get the SearchView and set the searchable configuration
 SearchManager searchManager = (SearchManager)    getSystemService(Context.SEARCH_SERVICE);
 SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
 searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

The search_hint is set correctly, but the line android:inputType="number" seems to have no effect, i.e. the numeric keypad doesn't appear.

Does anyone have a solution for this?

3 Answers3

2

Add this in your searchable.xml layout file:

android:numeric="decimal"

or If not useful then try,

android:inputType="phone"

And let me know what happen.

user370305
  • 108,599
  • 23
  • 164
  • 151
  • numeric is not an attribute of searchable, and unfortunately setting the inputType to phone doesn't help. – Riccardo Roveri Nov 28 '11 at 09:20
  • Look at this [Creating a Searchable Configuration](http://developer.android.com/guide/topics/search/search-dialog.html) then this [searchable](http://developer.android.com/guide/topics/search/searchable-config.html#searchable-element) then [inputType](http://developer.android.com/reference/android/R.attr.html#inputType). – user370305 Nov 28 '11 at 09:28
  • As you can see from my code, the inputType is set to "number" but the numeric keypad doesn't appear. – Riccardo Roveri Nov 28 '11 at 09:30
1

This should work :

SearchView searchView = new SearchView(getContext());
searchView.setInputType(InputType.TYPE_CLASS_NUMBER);
lokoko
  • 5,785
  • 5
  • 35
  • 68
  • Look like it's working, but only for Android API 14+. Am I right? (Question doesn't specify API version anyway) – NLemay Mar 01 '13 at 16:32
0

try this

android:inputType="phone"
mihail
  • 2,173
  • 19
  • 31