Answer the question
In order to leave comments, you need to log in
Why don't the icons in the options menu work?
Maybe someone has come across. Options menu icons are displayed, but do not react to pressing (Even Toast is not displayed). A toolbar was created in fragment_layout and a menu was placed there. Menu methods are overridden in the fragment Fragment
code
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)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question