Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getActionView is deprecated?

Today I decide to translate my android app from Java to Kotlin ! :) But I was very surprise when I type this :

val searchItem = menu.findItem(R.id.action_search) val searchView = MenuItemCompat.getActionView(searchItem) as SearchView 

And Android Studio told me : " 'getActionView(MenuItem!):View!' is deprecated. Deprecated in Java "

So before to ask you the solution I ask to Google what is the solution and I believed I find the solution : "Use getActionView() directly."

So I modified my code like this :

val searchView = MenuItemCompat.getActionView() as SearchView 

But getActionView() is still crossed so I don't understand at all...

I will be very happy if you can help me :) Thank you !

like image 733
Ross Thomas Avatar asked Jul 25 '17 14:07

Ross Thomas


1 Answers

The Javadoc says:

Use getActionView() directly.

Hence, what you should do is:

val searchView = searchItem.getActionView() as SearchView 
like image 53
Egor Avatar answered Sep 19 '22 14:09

Egor