android - No value passed for parameter item -


hello have code :

override fun oncreateoptionsmenu(menu: menu): boolean {         menuinflater.inflate(r.menu.menu_search, menu)         val searchitem = menu.finditem(r.id.action_search)         val searchview = menuitemcompat.getactionview() searchview          //*** setonquerytextfocuschangelistener ***         searchview.setonquerytextfocuschangelistener(object : view.onfocuschangelistener {              override fun onfocuschange(v: view, hasfocus: boolean) {              }         })          searchview.setonquerytextlistener(object : searchview.onquerytextlistener {              override fun onquerytextsubmit(query: string): boolean {                  return false             }              override fun onquerytextchange(searchquery: string): boolean {                 adapter!!.filter(searchquery.trim { <= ' ' })                 tvlistanimal.invalidate()                 return true             }         })           return true     } 

and found bug in line : val searchview = menuitemcompat.getactionview() searchview. beginning of code. indeed android studio told me no value passed parameter item don't know have put ?

thank lot ! !

edit : here menu_search.xml :

<?xml version="1.0" encoding="utf-8"?>       <menu xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:app="http://schemas.android.com/apk/res-auto"         xmlns:tools="http://schemas.android.com/tools"         tools:context=".settingsfragment">         <item android:id="@+id/action_search"             android:title="search"             android:icon="@drawable/ic_search"             app:showasaction="collapseactionview|always"             app:actionviewclass="android.support.v7.widget.searchview"             android:layout_width="wrap_content" />      </menu> 

i found in logcat :

 java.lang.classcastexception: android.support.v7.widget.searchview cannot cast android.widget.searchview 

the problem menuitemcompat.getactionview() requires menuitem passed in parameter:

val searchview = menuitemcompat.getactionview(searchitem) searchview 

if depracated in android version you're using (as seen here), should use instead:

val searchview = searchitem.getactionview() searchview 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -