Android Application Development (AND-401) — Question 104
Which of the following applies a context menu on a ListView (Choose two)?
Answer options
- A. ListView lv = getListView(); lv.registerForContextMenu()
- B. ListView lv = getListView(); registerForContextMenu(lv);
- C. ListView lv = (ListView) findViewByld(R.id.list_view_id); registerForContextMenu(lv)
- D. getListView().setContextMenuEnabled(true)
Correct answer: B, C
Explanation
Options B and C correctly demonstrate how to register a ListView for a context menu. Option A is incorrect because the method call to registerForContextMenu() on the ListView instance is not valid in this context. Option D is also incorrect since setContextMenuEnabled(true) is not a valid method for enabling context menus on a ListView.