Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError on calling MenuItem.collapseActionView

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?

like image 281
VSB Avatar asked Nov 29 '22 00:11

VSB


1 Answers

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.

like image 98
VSB Avatar answered Dec 09 '22 18:12

VSB