Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a SearchView's input type to numeric

I currently have a SearchView in my app's ActionBar (of which I am populating from an XML layout file) and I am trying to force it to only take numeric input. I've tried setting the android:inputType="number" attribute in XML, but it has no effect.

Does anyone know the source of this problem?

The XML menu resource:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/search"
        android:title="@string/menu_search"
        android:actionViewClass="android.widget.SearchView"
        android:icon="@drawable/ic_menu_search_holo_light"
        android:inputType="number" />       
</menu>
like image 980
Alex Lockwood Avatar asked Mar 03 '12 05:03

Alex Lockwood


1 Answers

setInputType on a searchView was introduced in API 14. To set it to number try :

searchView.setInputType(InputType.TYPE_CLASS_NUMBER);
like image 61
lokoko Avatar answered Sep 21 '22 19:09

lokoko