Skip to content

Instantly share code, notes, and snippets.

@hiking93
Created March 14, 2018 10:34
Show Gist options
  • Save hiking93/74445c64bf20199def3c474c60652405 to your computer and use it in GitHub Desktop.
Save hiking93/74445c64bf20199def3c474c60652405 to your computer and use it in GitHub Desktop.
Register context menu with ListView
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
registerForContextMenu(listView)
}
override fun onCreateContextMenu(menu: ContextMenu, view: View,
menuInfo: ContextMenu.ContextMenuInfo?) {
activity!!.menuInflater.inflate(R.menu.context_menu, menu)
}
override fun onContextItemSelected(item: MenuItem): Boolean {
val info = item.menuInfo as AdapterView.AdapterContextMenuInfo
val index = info.position
val view = info.targetView
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment