the problem that I present is with respect to the event onQueryTextListener
, I declare it as it used it in java previously, but it does not show the log when I submit a text or when I change the text.
This is the code of my fragment:
Fragment_producto.kt
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val vG = inflater!!.inflate(R.layout.fragment_producto, container, false)
vG.recycler_producto.layoutManager = LinearLayoutManager(activity)
vG.recycler_producto.hasFixedSize()
vG.recycler_producto.adapter = Producto_Adapter(activity,this)
vG.fab_scan.onClick {
IntentIntegrator.forSupportFragment(this@Fragment_producto).initiateScan()
}
adapter = vG.recycler_producto.adapter as Producto_Adapter
metodos.attachSwipeCheck(vG.recycler_producto)
metodos.attachSwipeWrong(vG.recycler_producto)
setHasOptionsMenu(true)
return vG
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
Log.i(TAG,"Llego a create optionsmenu")
activity.menuInflater.inflate(R.menu.menu_producto,menu)
/*val menuItem = menu.findItem(R.id.menu_search)
val search = menuItem.actionView as SearchView
searching(search)*/
super.onCreateOptionsMenu(menu, inflater)
}
override fun onPrepareOptionsMenu(menu: Menu) {
val menuItem = menu.findItem(R.id.menu_search)
val search = menuItem.actionView as SearchView
searching(search)
super.onPrepareOptionsMenu(menu)
}
private fun searching(search: SearchView){
search.onQueryTextListener {object: SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
Log.i(TAG,"Llego al querysubmit")
return false
}
override fun onQueryTextChange(newText: String): Boolean {
Log.i(TAG,"Llego al querytextchange")
return true
}
}}
}
Help me please.
Thanks
try changing your
searching
method to this:I haven't tested it but your brackets seem iffy. I think there should be
()
instead of{}
The method you are using
onQueryTextListener
(as compared tosetOnQueryTextListener
in my code above) does not compile for me. Do you use any extension methods there? Maybe that method takes a functionString->()
as an argument, so when you put theOnQueryTextListener
in the{}
you are just giving a lambda to the method as an argument that creates an object but never uses it.