Android Development: Relative Layout and View Positioning, Exams of Computer Programming

The use of the relativelayout in android development and how to specify the positioning of views within the layout. It covers the use of the android:layout_below attribute to position a view below another view. The document also covers other related topics such as the setimagebitmap method of the imageview class, handling persistent data using sharedpreferences, and working with sqlite databases. The content is drawn from various chapters of an android development textbook, covering a range of intermediate to advanced android programming concepts and techniques.

Typology: Exams

2023/2024

Available from 08/20/2024

DigitalexamsBanks
DigitalexamsBanks 🇵🇰

72 documents

1 / 161

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 01 - Quiz
Multiple Choice
1. Android apps can be distributed via:
A) the App Store.
B) the Android Market.
C) Google Play.
D) the Apple Store.
Ans: C
Complexity: Moderate
Ahead: Smart Phones and Their Operating Systems
Subject: Chapter 1
2. The programming language for Android app development is:
A) Java.
B) Python.
C) C++.
D) Perl.
Ans: A
Complexity: Easy
Ahead: Development Environment for Android Apps
Subject: Chapter 1
3. The red, green, and blue values of a gray shade are all equal. Including black and white, how many
shades of gray are there?
A) 8
B) 256
C) 16
D) 16.7 million
Ans: B
Complexity: Moderate
Ahead: Our First App: HelloAndroid
Subject: Chapter 1
4. The name of the directory where we should place the icon file for the app is:
A) drawable.
B) raw.
C) mipmap.
D) values.
Ans: C
Complexity: Difficult
Ahead: The App Manifest and the Gradle Build System
Subject: Chapter 1
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Android Development: Relative Layout and View Positioning and more Exams Computer Programming in PDF only on Docsity!

Chapter 01 - Quiz Multiple Choice

  1. Android apps can be distributed via: A) the App Store. B) the Android Market. C) Google Play. D) the Apple Store. Ans: C Complexity: Moderate Ahead: Smart Phones and Their Operating Systems Subject: Chapter 1
  2. The programming language for Android app development is: A) Java. B) Python. C) C++. D) Perl. Ans: A Complexity: Easy Ahead: Development Environment for Android Apps Subject: Chapter 1
  3. The red, green, and blue values of a gray shade are all equal. Including black and white, how many shades of gray are there? A) 8 B) 256 C) 16 D) 16.7 million Ans: B Complexity: Moderate Ahead: Our First App: HelloAndroid Subject: Chapter 1
  4. The name of the directory where we should place the icon file for the app is: A) drawable. B) raw. C) mipmap. D) values. Ans: C Complexity: Difficult Ahead: The App Manifest and the Gradle Build System Subject: Chapter 1
  1. Which of the following defines a valid String element? A) 20dp B) 20dp C) 16dp D) <my_name name="string">16dp</my_name> Ans: B Complexity: Moderate Ahead: Our First App: HelloAndroid Subject: Chapter 1
  2. The AppCompatActivity’s direct superclass is: A) MainActivity. B) Activity. C) AppCompat. D) Main. Ans: B Complexity: Moderate Ahead: Our First App: HelloAndroid Subject: Chapter 1 Short Answer
  3. The strings.xml file contains __________________ constants. Ans: string Complexity: Easy Ahead: Our First App: HelloAndroid Subject: Chapter 1
  4. AVD stands for __________________. Ans: Android Virtual Device Complexity: Easy Ahead: Running the App Inside the Emulator Subject: Chapter 1 True/False
  5. True or False? It is possible to preview a GUI XML file inside the environment without running the app. Ans: True Complexity: Easy Ahead: Our First App: HelloAndroid Subject: Chapter 1
  1. Which attribute do we use to specify the margin above a View? A) margin B) android:marginTop C) android:layout_marginTop D) android:layout_margin Ans: C Complexity: Moderate Ahead: GUI Components and More XML Attributes: Tip Calculator, Version 1 Subject: Chapter 2
  2. What is the correct definition of an item inside a style (assuming that the color abc is correctly defined in colors.xml)? A) B) @color/abc C) abc D) color/abc Ans: B Complexity: Difficult Ahead: Styles and Themes: Tip Calculator, Version 2 Subject: Chapter 2
  3. When a button is clicked on by the user, we want the method foo to execute. How do we do it (inside the Button element of the activity_main.xml file)? A) android:onClick="foo" B) android="foo" C) android:onClick="@activity/foo" D) onClick="foo" Ans: C Complexity: Difficult Ahead: Events and Simple Event Handling: Coding the Controller, Tip Calculator, Version 3 Subject: Chapter 2 True/False
  4. True or False? Button is a subclass of TextView. Ans: True Complexity: Easy Ahead: RelativeLayout, TextView, EditText, and Button: Tip Calculator, Version 0 Subject: Chapter 2 Short Answer
  5. The Model is the middleman between the __________________ and the Controller.

Ans: View Complexity: Easy Ahead: Model-View-Controller Architecture Subject: Chapter 2

  1. The superclass for layout classes is __________________. Ans: ViewGroup Complexity: Moderate Ahead: GUI Components Subject: Chapter 2
  2. The XML attribute that we use to give an id to a View is __________________. Ans: android:id Complexity: Moderate Ahead: RelativeLayout, TextView, EditText, and Button: Tip Calculator, Version 0 Subject: Chapter 2
  3. The __________________ interface provides three methods that are called when the text changes inside a TextView. Ans: TextWatcher Complexity: Difficult Ahead: More Event Handling: Tip Calculator, Version 4 Subject: Chapter 2 Chapter 03 - Quiz Multiple Choice
  4. What method do we use to set the number of rows in a GridLayout? A) setRowsCount B) setRowCount C) setRow D) setRows Ans: C Complexity: Moderate Ahead: Creating the GUI Programmatically, TicTacToe, Version 0 Subject: Chapter 3
  5. We used the GridLayout.Spec class in the chapter. What can we say about Spec? A) It is a private, static, inner class of GridLayout. B) It is a protected, static, inner class of GridLayout. C) It is a public, static, inner class of GridLayout. D) It is a public, static, independent class from GridLayout. Ans: A Complexity: Moderate

Short Answer

  1. The getDefaultDisplay method from the WindowManager interface returns a __________________ reference. Ans: Display Complexity: Easy Ahead: Creating the GUI Programmatically, TicTacToe, Version 0 Subject: Chapter 3 2.The View.OnClickListener interface can be implemented to handle a __________________ event on a View. Ans: click Complexity: Moderate Ahead: Event Handling: TicTacToe, Version 1 Subject: Chapter 3
  2. If TicTacToe is the class for the Model and we are inside the Activity class (the Controller), we can use an instance variable of type __________________ to represent the Model. Ans: TicTacToe Complexity: Easy Ahead: Integrating the Model to Enable Game Play: TicTacToe, Version 2 Subject: Chapter 3 Chapter 04 - Quiz Multiple Choice
  3. What XML element represents a row in a TableLayout? A) Row B) TableRow C) Table D) Rows Ans: B Complexity: Easy Ahead: Using a TableLayout for the Front Screen GUI: Mortgage Calculator App, Version 0 Subject: Chapter 4
  4. Using a RelativeLayout, which attribute do we use to specify that a View goes below another View? A) android:below B) android:belowView C) android:layout_belowView D) android:layout_below

Ans: D Complexity: Difficult Ahead: Using a RelativeLayout for the Second Screen GUI Subject: Chapter 4

  1. Using a RelativeLayout, which attribute do we use to specify that a View’s bottom matches the bottom of its parent View? A) android:layout_align B) android:layout_alignBottom C) android:layout_alignParentBottom D) android:layout_alignY Ans: C Complexity: Moderate Ahead: Using a RelativeLayout for the Second Screen GUI Subject: Chapter 4
  2. What is this in the following code? Intent myIntent = new Intent( this, DataActivity.class ); A) A DataActivity reference B) A reference to the current Activity C) An Intent D) A class Ans: B Complexity: Difficult Ahead: Connecting Two Activities: Mortgage Calculator App, Version 1 Subject: Chapter 4
  3. What is DataActivity in the following code? Intent myIntent = new Intent( this, DataActivity.class ); A) A subclass of Intent B) A reference to the current Activity C) An Intent D) An Activity class Ans: D Complexity: Difficult Ahead: Connecting Two Activities: Mortgage Calculator App, Version 1 Subject: Chapter 4
  4. When using a scale element for a scaling transition, what attribute do we use to define the x coordinate of a fixed point when scaling takes place? A) android:pivot B) android:X C) android:scaleX D) android:pivotX Ans: D Complexity: Difficult Ahead: Transitions between Activities: Mortgage Calculator App, Version 3 Subject: Chapter 4

Ahead: SQLite: Creating a Database, a Table, and Inserting Data: Candy Store App, Version 2 Subject: Chapter 5

  1. We have three activities in an app: MainActivity, InsertActivity, and DeleteActivity. How many activity elements should we have in the AndroidManifest.xml file? A) 0 B) 1 C) 2 D) 3 Ans: D Complexity: Easy Ahead: Deleting Data: Candy Store App, Version 3 Subject: Chapter 5 True/False
  2. True or False? We want to code a View, but we do not know how many radio buttons are in the View because we are retrieving the data from a database. We should code that View programmatically, not using an XML file. Ans: True Complexity: Easy Ahead: Deleting Data: Candy Store App, Version 3 Subject: Chapter 5
  3. True or False? We can use the following method of the Toast class to create a Toast: static Toast makeText( Context context, CharSequence text, int d ) The third parameter represents the duration or length of the Toast. Ans: True Complexity: Moderate Ahead: SQLite: Creating a Database, a Table, and Inserting Data: Candy Store App, Version 2 Subject: Chapter 5 Short Answer
  4. The XML element for a menu is __________________. Ans: Menu Complexity: Easy Ahead: Menus and Menu Items: Candy Store App, Version 0 Subject: Chapter 5
  5. The XML element for an item in a menu is __________________. Ans: Item

Complexity: Easy Ahead: Menus and Menu Items: Candy Store App, Version 0 Subject: Chapter 5

  1. The XML attribute that we use to specify an icon for a menu item is __________________. Ans: android:icon Complexity: Easy Ahead: Menus and Menu Items: Candy Store App, Version 0 Subject: Chapter 5
  2. The __________________ class encapsulates a table returned by a select SQL query. Ans: Cursor Complexity: Moderate Ahead: SQLite: Creating a Database, a Table, and Inserting Data: Candy Store App, Version 2 Subject: Chapter 5
  3. After we have created a Toast, we need to call the __________________ method so that the Toast is visible. Ans: show Complexity: Moderate Ahead: SQLite: Creating a Database, a Table, and Inserting Data: Candy Store App, Version 2 Subject: Chapter 5
  4. The removeAllViewsInLayout method of the ViewGroup class __________________ all the Views in the ViewGroup that calls it. Ans: removes Complexity: Easy Ahead: Running the Cash Register: Candy Store App, Version 5 Subject: Chapter 5 Chapter 06 - Quiz Multiple Choice
  5. The following instance variable of the Configuration class stores the height of the device in dp units, not including the status bar. A) height B) screenHeight C) screenHeightDp D) heightDp Ans: C Complexity: Moderate Ahead: The Configuration Class Subject: Chapter 6

Ahead: The Configuration Class Subject: Chapter 6

  1. The XML attribute for the right margin of a GUI component is __________________. Ans: android:layout_marginRight Complexity: Moderate Ahead: Strategy 2: One Layout XML File for Both Orientations, Modify the Layout by Code Subject: Chapter 6
  2. The XML attribute for the bottom margin of a GUI component is __________________. Ans: android:layout_marginBottom Complexity: Moderate Ahead: Strategy 2: One Layout XML File for Both Orientations, Modify the Layout by Code Subject: Chapter 6
  3. The getDimensionPixelSize method of the Resources class returns the number of __________________ of a resource given its id. Ans: pixels Complexity: Difficult Ahead: Strategy 3: Manage Layout and Orientation 100% by Code Subject: Chapter 6 Chapter 07 - Quiz Multiple Choice
  4. We want to be able to compare the starting coordinate of a touch with the ending coordinate of a touch. How can we do it? A) We cannot compare those coordinates. B) We can compare them inside the onTouch method when it is called; nothing additional needed. C) Store the ending coordinate in an instance variable and compare it to the starting coordinate of the touch inside the onTouch method. D) Store the starting coordinate in an instance variable and compare it to the ending coordinate of the touch inside the onTouch method. Ans: D Complexity: Difficult Ahead: Moving the Pieces, Puzzle App, Version 1 Subject: Chapter 7
  5. The getX method of MouseEvent returns: A) the x coordinate of the touch within the screen. B) the x coordinate of the touch within the View where the touch occurred. C) the x coordinate of the top of the screen. D) the x coordinate of the top of the View where the touch occurred. Ans: B

Complexity: Moderate Ahead: Detecting a Touch Event Subject: Chapter 7 True/False

  1. True or False? We can enable the user to move a TextView. Ans: True Complexity: Easy Ahead: Moving the Pieces, Puzzle App, Version 1 Subject: Chapter 7 Short Answer
  2. One of the things we must do to handle touch events is create an object of a class that __________________ View.OnTouchListener. Ans: implements Complexity: Moderate Ahead: Detecting a Touch Event Subject: Chapter 7
  3. One of the things we must do to handle touch events is register an object of a class that implements View.OnTouchListener on one or more __________________. Ans: Views Complexity: Moderate Ahead: Detecting a Touch Event Subject: Chapter 7
  4. The public field of the ViewGroup.MarginLayoutParams class defining a bottom margin is __________________. Ans: bottomMargin Complexity: Easy Ahead: Handling a Swipe Event: Moving a TextView Subject: Chapter 7
  5. The public field of the ViewGroup.MarginLayoutParams class defining a top margin is __________________. Ans: topMargin Complexity: Easy Ahead: Handling a Swipe Event: Moving a TextView Subject: Chapter 7
  1. What method of the TimerTask class do we need to override and is also called automatically? A) thread B) go C) task D) run Ans: D Complexity: Difficult Ahead: Animating an Object: Flying the Duck, Duck Hunting App, Version 1 Subject: Chapter 8
  2. Following is the API for one of the load methods of the SoundPool class: int load( Context context, int i, int priority ) What does i represent? A) A resource B) The volume of the sound C) The length of the sound D) The number of times we will play the sound Ans: A Complexity: Difficult Ahead: Playing a Sound: Shooting, Collision Detection, Duck Hunting App, Version 3 Subject: Chapter 8
  3. How do we access the width of a Bitmap object reference named b? A) int w = Bitmap.width; B) int w = b.getWidth( ); C) int b = w.getWidth( ); D) int Bitmap.b = getWidth( ) Ans: B Complexity: Moderate Ahead: Graphics Subject: Chapter 8 True/False
  4. True or False? The setColor method of the Paint class takes an int parameter; when calling this method, it is possible to pass a hexadecimal number as its argument. Ans: True Complexity: Moderate Ahead: Graphics Subject: Chapter 8
  5. True or False? In the following statement, c is a Canvas reference, b is a Bitmap reference, r is a Rect reference, and p is a Paint reference. c.drawBitmap( b, null, r, p ); The bitmap will be drawn in its entirety.

Ans: True Complexity: Moderate Ahead: Making a Custom View, Drawing, Duck Hunting App, Version 0 Subject: Chapter 8

  1. True or False? It is possible to move a line drawn on the screen by moving your finger on the screen. Ans: True Complexity: Easy Ahead: Handling Touch Events: Moving the Cannon and Shooting, Duck Hunting App, Version 2 Subject: Chapter 8
  2. True or False? The drawLine method of the Canvas class has this API: void drawLine( float a, float b, float c, float d, Paint paint ) In this API, ( a, b ) represents the coordinate of the starting point of the line and ( c, d ) represents the coordinate of the ending point of the line. Ans: True Complexity: Moderate Ahead: Graphics Subject: Chapter 8 Short Answer
  3. The BitmapFactory is a factory class to create __________________ objects. Ans: Bitmap Complexity: Easy Ahead: Graphics Subject: Chapter 8
  4. The postInvalidate method of the View class that has no parameter triggers a call to the __________________ method and refreshes the whole View. Ans: onDraw Complexity: Moderate Ahead: Animating an Object: Flying the Duck, Duck Hunting App, Version 1 Subject: Chapter 8
  5. The SoundPool class, part of the __________________ package, enables us to load a sound and play it. Ans: android.media Complexity: Moderate Ahead: Playing a Sound: Shooting, Collision Detection, Duck Hunting App, Version 3 Subject: Chapter 8

B) fragmentView C) getView D) getFragmentView Ans: C Complexity: Moderate Ahead: Defining a Fragment Using a Layout XML File and Adding the Fragment to an Activity by Code, Hangman, App Version 2 Subject: Chapter 9 True/False

  1. True or False? It is possible to define a fragment programmatically without using a layout XML file. Ans: True Complexity: Easy Ahead: Defining and Adding a Fragment to an Activity by Code, Hangman, App Version 3 Subject: Chapter 9
  2. True or False? If we call the getActivity method inside a user-defined Fragment class and assign the return value to a user-defined Activity class, the Fragment class is not usable with a different user-defined Activity class. To make it reusable with a different user-defined Activity class, we use an interface inside the user-defined Fragment class and have our user-defined Activity class implement that interface. Ans: True Complexity: Moderate Ahead: Making a Fragment Reusable, Hangman, App Version 6 Subject: Chapter 9 Short Answer
  3. To get a reference to a fragment using its id, we call the __________________ method from the FragmentManager class. Ans: findFragmentById Complexity: Moderate Ahead: Defining a Fragment Using a Layout XML File and Adding the Fragment to an Activity by Code, Hangman, App Version 2 Subject: Chapter 9
  4. A fragment can be defined in an XML layout file using a __________________ XML element. Ans: fragment Complexity: Moderate Ahead: Defining and Adding a Fragment to an Activity Using a Layout XML File, Hangman, App Version 0 Subject: Chapter 9
  1. If we intend to call a method of our Activity class with the Activity of a fragment, it is important to __________________ the return object of the getActivity method to that type of Activity. Ans: cast Complexity: Difficult Ahead: Defining a Fragment Using a Layout XML File and Adding the Fragment to an Activity by Code, Hangman, App Version 2 Subject: Chapter 9
  2. The __________________ method of the InputMethodManager class can be used to close or hide a keyboard. Ans: hideSoftInputFromWindow Complexity: Difficult Ahead: Improving the GUI: Processing the Keyboard Input Directly, Hangman, App Version 7 Subject: Chapter 9
  3. The IBinder interface encapsulates a(n) __________________ object. Ans: remotable Complexity: Difficult Ahead: Improving the GUI: Processing the Keyboard Input Directly, Hangman, App Version 7 Subject: Chapter 9
  4. We can obtain an ____________ reference by calling the getSystemService of the Context class. Ans: InputMethodManager Complexity: Difficult Ahead: Improving the GUI: Processing the Keyboard Input Directly, Hangman, App Version 7 Subject: Chapter 9 Chapter 10 - Quiz Multiple Choice
  5. What method of the Intent class do we call to put a value mapped to a key in an Intent? A) put B) putKey C) putValue D) putExtra Ans: D Complexity: Difficult Ahead: Voice Recognition Part A, App Version 0 Subject: Chapter 10
  6. What is not included in a CameraUpdate object? A) Latitude B) Longitude C) Resource id