Questions and Answers
What is the purpose of organizing resources into specially named directories in Android?
To provide alternative resources for specific device configurations at runtime.
What directory do all resources in an Android project need to be stored in?
/res directory
How does Android handle the selection of resources based on device configuration?
Android automatically selects the correct resources without requiring user intervention.
Describe the role of the R.java file in accessing resources programmatically.
Signup and view all the answers
In which sub-directory are tween animations stored in an Android project?
Signup and view all the answers
Why is it beneficial to keep non-code resources external to the application's code?
Signup and view all the answers
What are color state list resources used for in Android applications?
Signup and view all the answers
What function does the ADT plug-in serve in the management of resources in Android development?
Signup and view all the answers
What method is used to set a listener for the negative button in an AlertDialog?
Signup and view all the answers
Which class must you extend to create an Android activity like MainActivity?
Signup and view all the answers
What is the purpose of the setTitle
method in the AlertDialog.Builder?
Signup and view all the answers
What layout method is called to display the custom view within the AlertDialog?
Signup and view all the answers
How does the AlertDialog react when the positive button is clicked according to MainActivity's implementation?
Signup and view all the answers
What does the finish()
method do in the negative button's click listener?
Signup and view all the answers
What is the role of a theme in Android app development?
Signup and view all the answers
In which lifecycle method is the AlertDialog created and shown in MainActivity?
Signup and view all the answers
What directory do you need to copy the ICLS file to for theme application in Android Studio?
Signup and view all the answers
What are the four arguments required by the add() method when creating a menu item?
Signup and view all the answers
Which method do you override to display the options menu in an activity?
Signup and view all the answers
How can you assign a keyboard shortcut to a menu item in Android?
Signup and view all the answers
What does the MenuChoice() method accomplish in the context of Android menus?
Signup and view all the answers
What is the purpose of the android:theme attribute in the AndroidManifest.xml file?
Signup and view all the answers
What function is used to insert an image into a menu item?
Signup and view all the answers
What is the purpose of the CreateMenu() method in Android?
Signup and view all the answers
What are the two types of intents in Android, and how do they differ?
Signup and view all the answers
What is the purpose of a dialog in Android applications?
Signup and view all the answers
Why should the Dialog class not be instantiated directly in Android?
Signup and view all the answers
What features can an AlertDialog in Android include?
Signup and view all the answers
Describe the three regions that compose the Android AlertDialog.
Signup and view all the answers
What types of action buttons should be included in an AlertDialog, and what is their purpose?
Signup and view all the answers
When is it acceptable to omit the title in an AlertDialog?
Signup and view all the answers
What is the difference between DatePickerDialog and TimePickerDialog?
Signup and view all the answers
What method is called when the MENU button is pressed in an Android activity?
Signup and view all the answers
How can you associate a context menu with a view in an Android activity?
Signup and view all the answers
In the provided code, what action occurs when a menu item is selected?
Signup and view all the answers
What is the purpose of the Toast message in the onOptionsItemSelected() method?
Signup and view all the answers
What is the correct method to inflate a menu in an activity?
Signup and view all the answers
Why would you register a view for a context menu in an Android activity?
Signup and view all the answers
What class needs to be extended to create a custom activity for menus in Android?
Signup and view all the answers
What is displayed when the user long-clicks on a Button view if a context menu is set up?
Signup and view all the answers
What function does the onCreateContextMenu() method serve?
Signup and view all the answers
What should be returned at the end of the onOptionsItemSelected() method if none of the menu items were selected?
Signup and view all the answers
Study Notes
Android Resources
- Android organizes alternative resources in specially named directories for device configurations.
- Resources are selected at runtime based on device characteristics, language, and other settings.
- Common resource types include layouts, graphics, strings, and animations, which are stored in the
/res
directory. - Graphics files are specifically stored in the
/res/drawable
folder. - Externalizing resources simplifies management and allows updates without altering the code.
- The ADT plug-in detects new resource files and compiles them into
R.java
, enabling programmatic access to resources.
Resource Types
-
Animation Resources:
- Tween animations stored in
/res/anim/
, accessed viaR.anim
. - Frame animations stored in
/res/drawable/
, accessed viaR.drawable
.
- Tween animations stored in
-
Color State List Resource:
- Defines colors that change based on the view's state.
Intents
- Two categories of intents:
- Public intents registered with the system, accessible by any application.
- Private intents used within a single application.
Dialogs
-
Dialogs are small windows prompting user action without filling the screen.
-
Base class:
Dialog
; use subclasses likeAlertDialog
,DatePickerDialog
, orTimePickerDialog
for specific functionalities. -
AlertDialog:
- Composed of a title, content area, and action buttons (max of three: positive, negative, and neutral).
- Positive button accepts an action, negative cancels it, and neutral allows proceeding without confirmation.
Methods for AlertDialog
-
setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener)
: Sets a listener for the negative button. -
setTitle(CharSequence title)
: Sets Dialog title. -
setView(View view)
: Sets a custom view for the Dialog. -
show()
: Creates the dialog instance and displays it.
Themes in Android
- Themes apply to apps, activities, or view hierarchies, affecting all supported attributes.
- Themes can be downloaded, copied to the configuration directory
%USERPROFILE%/.AndroidStudio/config/colors
, and applied in the manifest.
Menus
-
Two main types of menus: Options Menu and Context Menu.
-
Options Menu:
- Activated by the MENU key; defined in
onCreateOptionsMenu()
and handled inonOptionsItemSelected()
.
- Activated by the MENU key; defined in
-
Context Menu:
- Associated with specific views; activated via long-click.
- Requires setting up a context menu listener on the view using
setOnCreateContextMenuListener()
.
Sample Code Overview
- Includes implementation examples for setting up AlertDialog and menus in
MainActivity.java
and XML layout files, demonstrating how to create and manage user interactions effectively.
Settings
- Android provides a framework for defining and displaying application preferences easily with minimal code.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge on Android's resource management system. This quiz covers how Android selects resources based on device configurations such as screen size and language settings. Sharpen your understanding of optimizing UI and data resources for different devices.