Free AND-401 Exam Braindumps (page: 9)

Page 8 of 58

Javascript is enabled by default in a WebView

  1. True
  2. False

Answer(s): B

Explanation:

If the web page you plan to load in your WebView use JavaScript, you must enable JavaScript for your WebView.


Reference:

http://developer.android.com/guide/webapps/webview.html



How to enable JavaScript in WebView?

  1. myWebView. setJavaScriptEnabled(true);
  2. myWebView.getJavaScriptSettings.setEnabled(true)
  3. myWebView.getSettings().setJavaScriptEnabled(true);
  4. Java script is always enabled in WebView

Answer(s): C

Explanation:

JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView. You can retrieve WebSettings with getSettings(), then enable JavaScript with setJavaScriptEnabled ().

For example:
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);


Reference:

http://developer.android.com/guide/webapps/webview.html



What two methods you have to override when implementing Android context menus?

  1. onCreateOptionsMenu, onCreateContextMenu
  2. onCreateContextMenu, onContextItemSelected
  3. onCreateOptionsMenu, onOptionsItemSelected
  4. onCreateOptionsMenu, onContextItemSelected

Answer(s): B

Explanation:

Need to create context menu. For this need to override this method:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("My Context Menu");
menu.add(0, NEW_MENU_ITEM, 0, "new");
menu.add(0, SAVE_MENU_ITEM, 1, "save");
}
And last one need to handle menu clicks:
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case NEW_MENU_ITEM:
doSomething();
break;
case SAVE_MENU_ITEM:
doSomething();
break;
}
return super.onContextItemSelected(item);
}


Reference:

https://thedevelopersinfo.wordpress.com/2009/11/06/using-context-menus-in-android/



What two methods you have to override when implementing Android option menus?

  1. onCreateOptionsMenu, onCreateContextMenu
  2. onCreateContextMenu, onContextItemSelected
  3. onCreateOptionsMenu, onOptionsItemSelected
  4. onCreateOptionsMenu, onContextItemSelected

Answer(s): C

Explanation:

To specify the options menu for an activity, override onCreateOptionsMenu().
When the user selects an item from the options menu (including action items in the app bar), the system calls your activity's onOptionsItemSelected() method. This method passes the MenuItem selected. You can identify the item by calling getItemId(), which returns the unique ID for the menu item (defined by the android:id attribute in the menu resource or with an integer given to the add() method). You can match this ID against known menu items to perform the appropriate action.
For example:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Etc.


Reference:

http://developer.android.com/guide/topics/ui/menus.html






Post your Comments and Discuss Android AND-401 exam with other Community members:

AND-401 Discussions & Posts