Может,кто сталкивался.Иконки options menu отображаются,но никак не реагируют на нажатие(Даже Toast не отображают).Был создан toolbar в fragment_layout туда помещено меню.Методы меню переопределены во фрагменте
Код фрагмента
class BlankFragment2 : Fragment() {
private final val URLCOUNTRY = "
https://restcountries.eu/rest/v2/"
lateinit var myAdapter: MyAdapter
lateinit var rcView: RecyclerView
lateinit var linearLayoutManager: LinearLayoutManager
lateinit var responseBody: MutableList
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_blank2, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
rcView = view.findViewById(R.id.rcView)
linearLayoutManager = LinearLayoutManager(this.context)
rcView.layoutManager = linearLayoutManager
rcView.hasFixedSize()
getData()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
fun getData() {
val retrofit = getRetrofit(URLCOUNTRY).create(RetrofitService::class.java)
val retrofitData = retrofit.getCountryList()
retrofitData.enqueue(object : Callback?> {
override fun onResponse(
call: Call?>,
response: Response?>
) {
responseBody = response.body()!!
myAdapter = MyAdapter(responseBody)
myAdapter.notifyDataSetChanged()
rcView.adapter = myAdapter
}
override fun onFailure(
call: Call?>,
t: Throwable
) {
t.printStackTrace()
}
})
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.user_info_menu, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.sorted -> Toast.makeText(this.context, "Jjkjkj", Toast.LENGTH_SHORT).show()
}
return super.onOptionsItemSelected(item)
}
}