Using android support library I implemented ActionBar (android.support.v7.app.ActionBar). Meanwhile I was trying to interact with SearchView and tried to collapse SearchItem using below method:
searchItem.collapseActionView();
seachItem is of type MenuItem. This lead to below exception:
java.lang.NoSuchMethodError: android.view.MenuItem.collapseActionView
So how should i collapse SearchItem?
Instead of using:
searchItem.collapseActionView();
I must use static method from android.support.v4.view.MenuItemCompat:
MenuItemCompat.collapseActionView(searchItem);
It seems to obvious at the moment but it took several hours to wonder that available codes at websites usually intended to run on (android.app.ActionBar) library (API 11 and higher) not on Support Library V7 (android.support.v7.app.ActionBar) which got its own methods that are different in some cases like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With