MCQs / Computer Science / Lab: Menus and Messages

Lab: Menus and Messages MCQs — Computer Science

12 multiple-choice questions on Lab: Menus and Messages from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.

1. Which component shows a brief message with an action button at the bottom of the screen?

  1. Toast
  2. Spinner
  3. ProgressBar
  4. Snackbar

Answer: D) Snackbar

Explanation: Snackbar can include one action such as OK/Undo.

Discuss this question

2. item.itemId in onOptionsItemSelected gives:

  1. The number of items
  2. The item's icon
  3. The activity ID
  4. The ID of the menu item that was clicked

Answer: D) The ID of the menu item that was clicked

Explanation: itemId identifies the selected item.

Discuss this question

3. The menu XML for this lab is saved as:

  1. assets/menu.xml
  2. res/layout/mainmenu.xml
  3. res/menu/mainmenu.xml
  4. res/values/menu.xml

Answer: C) res/menu/mainmenu.xml

Explanation: Menu resources go in res/menu.

Discuss this question

4. Which attribute namespace is used for showAsAction with AppCompat?

  1. tools:showAsAction
  2. android:showAsAction
  3. app:showAsAction
  4. menu:showAsAction

Answer: C) app:showAsAction

Explanation: With AppCompat/Material, showAsAction uses the app namespace.

Discuss this question

5. PopupMenu(this, anchor) shows the menu:

  1. In a new activity
  2. At the top of the screen
  3. Anchored to the given view
  4. As a notification

Answer: C) Anchored to the given view

Explanation: A popup menu is anchored to the view passed to its constructor.

Discuss this question

6. Which attribute changes the order of items in the menu?

  1. android:priority
  2. android:position
  3. android:index
  4. android:orderInCategory

Answer: D) android:orderInCategory

Explanation: orderInCategory controls item ordering.

Discuss this question

7. A context menu opens when the user:

  1. Taps the overflow icon
  2. Shakes the device
  3. Long-presses a view registered with registerForContextMenu()
  4. Swipes from the left

Answer: C) Long-presses a view registered with registerForContextMenu()

Explanation: Context menus appear on long press.

Discuss this question

8. Items can be added to a menu in code using:

  1. addView()
  2. menu.insertItem()
  3. menu.add(groupId, itemId, order, title)
  4. setItems()

Answer: C) menu.add(groupId, itemId, order, title)

Explanation: Menu.add() creates items programmatically.

Discuss this question

9. The crash "This Activity already has an action bar supplied by the window decor" happens because:

  1. The app has no internet
  2. Toast is called too often
  3. A theme with an ActionBar is used together with setSupportActionBar(toolbar)
  4. The menu XML is missing

Answer: C) A theme with an ActionBar is used together with setSupportActionBar(toolbar)

Explanation: Use a NoActionBar theme when you set a Toolbar as the app bar.

Discuss this question

10. Items with showAsAction="never" appear:

  1. In a context menu
  2. In the overflow (⋮) menu
  3. Nowhere
  4. As icons in the bar

Answer: B) In the overflow (⋮) menu

Explanation: never always places the item in the overflow menu.

Discuss this question

11. Which object inflates the menu XML inside an activity?

  1. supportFragmentManager
  2. layoutInflater
  3. packageManager
  4. menuInflater

Answer: D) menuInflater

Explanation: menuInflater.inflate(R.menu.mainmenu, menu) builds the menu.

Discuss this question

12. What must onCreateOptionsMenu return for the menu to be shown?

  1. null
  2. The menu ID
  3. false
  4. true

Answer: D) true

Explanation: Returning true displays the menu.

Discuss this question

Practise Lab: Menus and Messages MCQs

More Computer Science chapters