Android
AND-401 · Question #125
Consider the following : <?xml version="1.0" encoding="utf-8"?> <item android:id="@+id/create_new" android:title="@string/create_new" /> <item android:id="@+id/open" android:title="@string/open" />…
The correct answer is B. The developer did not include a case that corresponds to the menu item in method. See the full explanation below for the reasoning.
Question
Consider the following :
<?xml version="1.0" encoding="utf-8"?> <item android:id="@+id/create_new" android:title="@string/create_new" /> <item android:id="@+id/open" android:title="@string/open" /> </menu> public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.create_new:newFile(); return true default:
return super.onOptionsItemSelected(item); } } Upon clicking on one of the menu items, the application did not behave as intended. Which of the following might be the cause of this problem?
Options
- AThe developer did not set onClickListener on the menu item.
- BThe developer did not include a case that corresponds to the menu item in method
- CThe developer should create onOptionsItemSelected method for each menu item.
- DThe developer should add the item to the menu resource file.
How the community answered
(24 responses)- A4% (1)
- B75% (18)
- C17% (4)
- D4% (1)
Community Discussion
No community discussion yet for this question.