Podcast
Questions and Answers
Which of the following statements best describes the relationship between View and ViewGroup in Android UI development?
Which of the following statements best describes the relationship between View and ViewGroup in Android UI development?
- View and ViewGroup are interfaces that must be implemented to create UI elements.
- View and ViewGroup are interchangeable terms for UI widgets in Android.
- View is a subclass of ViewGroup, serving as a basic UI widget, while ViewGroup is its parent class.
- ViewGroup is a subclass of View, acting as an invisible container to manage the layout of child views. (correct)
When defining an android:id
attribute in XML, what is the significance of the plus sign (+) before the resource type?
When defining an android:id
attribute in XML, what is the significance of the plus sign (+) before the resource type?
- It denotes that the resource ID is a reference to an existing resource in a different XML file.
- It indicates that the resource is a system-defined ID and should not be modified.
- It signifies that the resource ID is optional and can be omitted without causing errors.
- It specifies that the resource ID is being defined for the first time and needs to be created. (correct)
Which unit of measurement is recommended for defining sizes of views to ensure UI elements maintain consistent physical dimensions across devices with varying screen densities?
Which unit of measurement is recommended for defining sizes of views to ensure UI elements maintain consistent physical dimensions across devices with varying screen densities?
- Millimeters (mm)
- Density-independent Pixels (dp) (correct)
- Pixels (px)
- Inches (in)
Why is it recommended to externalize strings as resources in Android app development?
Why is it recommended to externalize strings as resources in Android app development?
How do you associate an event handler method defined in a Java Activity with a View element in an XML layout file?
How do you associate an event handler method defined in a Java Activity with a View element in an XML layout file?
What is the purpose of the Toast
class in Android?
What is the purpose of the Toast
class in Android?
In the context of Android resources, what is the purpose of the 'R' class?
In the context of Android resources, what is the purpose of the 'R' class?
What is the recommended unit for specifying text size in Android XML layouts, and why?
What is the recommended unit for specifying text size in Android XML layouts, and why?
What is the primary function of an Intent in Android?
What is the primary function of an Intent in Android?
What is the key difference between an explicit and an implicit Intent?
What is the key difference between an explicit and an implicit Intent?
When sending data between activities using an Intent, which method is used to attach data to the Intent?
When sending data between activities using an Intent, which method is used to attach data to the Intent?
What is the purpose of the App Bar (Action Bar) in Android app development?
What is the purpose of the App Bar (Action Bar) in Android app development?
What is the role of the NavController in the Android Navigation Component?
What is the role of the NavController in the Android Navigation Component?
When using the Navigation Component, what is the purpose of an AppBarConfiguration object?
When using the Navigation Component, what is the purpose of an AppBarConfiguration object?
What is the primary advantage of using a RecyclerView over a ListView in Android?
What is the primary advantage of using a RecyclerView over a ListView in Android?
When would you typically choose to use Shared Preferences for data storage in Android?
When would you typically choose to use Shared Preferences for data storage in Android?
What is the purpose of Room Persistence Library?
What is the purpose of Room Persistence Library?
What benefit does the Volley library provide for making HTTP requests in Android?
What benefit does the Volley library provide for making HTTP requests in Android?
When using implicit intents, how can you ensure that your app gracefully handles the scenario where no other app on the device can handle the specified intent?
When using implicit intents, how can you ensure that your app gracefully handles the scenario where no other app on the device can handle the specified intent?
How do you request a runtime permission in Android?
How do you request a runtime permission in Android?
Flashcards
View
View
A user interface element that makes up what you see on a device.
ViewGroup
ViewGroup
Invisible containers that define how child views are laid out.
android:text
android:text
Text to display.
android:id
android:id
Signup and view all the flashcards
Density-independent Pixels (dp)
Density-independent Pixels (dp)
Signup and view all the flashcards
Event Handlers
Event Handlers
Signup and view all the flashcards
Activity
Activity
Signup and view all the flashcards
Activity UI
Activity UI
Signup and view all the flashcards
Intent
Intent
Signup and view all the flashcards
Explicit Intent
Explicit Intent
Signup and view all the flashcards
Implicit Intent
Implicit Intent
Signup and view all the flashcards
Fragment
Fragment
Signup and view all the flashcards
Controller
Controller
Signup and view all the flashcards
AppBarConfiguration object
AppBarConfiguration object
Signup and view all the flashcards
Navigation Drawer
Navigation Drawer
Signup and view all the flashcards
ListView
ListView
Signup and view all the flashcards
RecyclerView
RecyclerView
Signup and view all the flashcards
Shared Preferences
Shared Preferences
Signup and view all the flashcards
Room Persistence
Room Persistence
Signup and view all the flashcards
Volley
Volley
Signup and view all the flashcards
Study Notes
- A view is everything that is visible on the screen.
Views
- View subclasses are building blocks for the user interface.
- Android system provides over 100 view types, and are children of the View class.
- Buttons, EditText, Slider, CheckBox, and RadioButton are all examples of view subclasses.
View Groups
- ViewGroup and View hierarchy are used to build the graphical user interface.
- View objects are usually the UI widgets such as buttons or text fields
- ViewGroup objects are containers that define how child views are laid out in a grid or a vertical list and are invisible.
- Layouts are specific types of ViewGroups, subclasses of ViewGroup, with child views.
- Layouts can be in a row, column, grid, table, or absolute position.
- Common layout classes are LinearLayout, ConstraintLayout., GridLayout, and TableLayout.
- The layout editor is a view hierarchy that is present on the screen.
Creating Views and Layouts
- Views and layouts can be created in the Android Studio layout editor with XML or Java code.
- The XML editor allows for intermixing between the visual representation and the XML code.
Android Studio Layout Editor
- The XML layout file is edited using design and text tabs.
- Palette pane, component tree, design and blueprint panes, and attributes tab are provided.
Attributes
- Layout is created in XML with common TextView attributes.
android:text
displays text.android:textColor
styles the color of text.android:textAppearance
formats predefined style or theme.android:textSize
sets text size in sp.android:textStyle
types text in normal, bold, italic, or bold|italic.android:typeface
fonts text in normal, sans, serif, or monospace.android:lineSpacingExtra
adds extra space between lines in sp.
ID Attribute
android:id="@+id/textView_message"
uniquely identifies the view that is used to reference and manipulate the object.- The at sign (@) is required when referring to any resource object from XML and is followed by the resource type, a slash, and the resource name.
- The plus sign (+) before the resource type is required only when defining a resource ID for the first time.
Width & Height
android:layout_width
andandroid:layout_height
allow the user to define specific values for attributes.- Android supports various measurements, including:
- px (Pixels): Actual dots on the screen.
- in (Inches): Physical size of the screen.
- mm (Millimeters): Physical size of the screen.
- pt (Points): 1/72 of an inch.
- dp (Density-independent Pixels): Keep UI elements the same physical size across screen densities.
- The "wrap_content" value specifies that the view should be only as big as needed to fit the contents, instead of using specific sizes.
- If "match_parent" is used, the view fills its parent.
String Resources
- Each string should be specified as a resource when adding text to the user interface.
- Ul text can be managed in a single location, which makes it easier to find and update, with string resources.
- Externalizing the strings also allows to localize the app to different languages by providing alternative definitions for each string resource.
- The Android project includes a string resource file at res/values/strings.xml.
- A new string named "welcome_message" with the value "Welcome to CENG435" must be added.
- The string variable name is "welcome message" and the content that is displayed on the screen is "Welcome to CENG435."
- In the string.xml file, there are 2 strings; one was automatically added by Android Studio (app_name) while the other was added manually (welcome_message).
Hint
- The hint is a default string to display when the EditText field is empty and disappears once the user starts typing.
Toasts
- Provides simple feedback about an operation in a small popup.
- It only fills the amount of space required for the message and the current activity remains visible and interactive.
- It automatically disappears after a timeout.
Example:
Toast.makeText(this, "Type your message here", Toast.LENGTH_SHORT).show();
- In UI, click, tap, and drag are examples.
Events
- Something that happens in the UI, such as click, tap, or drag, or in the device, such as detected activity like walking, driving, or tilting.
- Events are "noticed" by the Android system.
- Event handlers are methods that do something in response to a click.
- A method, called an event handler, is triggered by a specific event and does something in response to the event.
Event Handler for Button Click
- Attach handler to view in XML layout with
android:onClick="addValues"
must have a signature that is public, void return, and a view. - Implement handler in Java activity with the code that adds values and displays the result public void addValues(View view).
Resources and Measurements
- Static data is separated from code in resources such as strings, dimensions, images, menu text, colors, and styles.
Storing resources
- Resources and resource files stored in res folder.
Layout
- R.layout.activity_main, sets the content.
View
- R.id.recyclerView rv = (RecyclerView)findViewById(R.id.recyclerView, identifies the view.
String
- String: In Java: R.string.title in XML: android:text="@string/title", gets the title in either Java or XML.
Measurements
- Density-independent Pixels (dp) are used for views.
- Scale-independent Pixels (sp) are used for text.
- Device-dependent or density dependent units are avoided.
- Actual Pixels (px) and actual measuring (in) do not need to be used.
Activity
- Represents one window (one screen) as an application component.
- Is a Java class, typically with one Activity in one file.
- Are loosely tied together to make up an app.
- "Main activity" is the first Activity user sees
- Has a UI layout that is usually defined in one or more XML files.
Create new Activities
- Define layout in XML; define Activity Java class, extends AppCompatActivity; connect Activity with Layout, set content view in
onCreate()
; declare Activity in the Android manifest. - To connect, resource is layout in the XML file and MainActivity needs to include intent filter to start from launcher.
Intents
- Describes an operation to be performed, object used to request an action from another app component via the Android system, and originator.
- Starting an activity can click a button that starts a new Activity for text entry, by clicking Share that opens an app to post a photo.
- Initiate downloading a file in the background for a service or delivery.
Types of Intents
- Explicit intent starts a specific Activity requesting the system find an Activity that can handle this request (asks the system).
- Starting activity with specific Activity uses an explicit intent: Intent intent = new Intent(this, ActivityName.class);
Navigation Using Intent Object
- When the user clicks on SEND, an explicit intent is created to send text entered to the second activity, including how to manage the intent.
- All methods provided are placed inside onClick of a button.
How to extract value from EditText
- Extract value from the EditText view using getText(), saving it to a new string message. The intent is created and set to the class name responsible for the second activity, where this is the context of MainActivity.
- To fill the intent object with data, use putExtra([user-chosen name], [value]).
- Start or call the second activity to make your phone switch to another screen view by displaying the layout of the second activity. Main activity coding is completed through pressing the button.
- Value of string entered by the user is sent and recieved. The value sent in an intent object is also received from same intent object.
- Grabbing the intent, extracting the extra from it, and setting the value to the TextView view are used along with the code to display the message.
App Bar
- Also known as the action bar, is one of the most important design elements in the app and provides a familiar visual structure with interactive elements, making the app consistent with others.
- The major functions are to give the app identity, indicates location, gives predictable access to important actions like search, support navigation, and view switching through tabs or menus.
- To add the toolbar and set it as the bar for the activity.
Adding actions to bars
- Creating a menu XML file in res/menu and then use setting the Inflate menu in the toolbar:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity_actions, menu); return super.
Responding to actions
public boolean onOptionsItemSelected(MenuItem item) {
- Use an if, else if structure to see which action was selected.
- To include a Searchview widget to the app bar, then menu item and action must be added.
- String data container to display the data that is received between destinations, bundle arguments include getString() to get data.
Navigation UI
- Uses AppBarConfiguration object to manage Navigational behavior in the upper left corner of the app, such as a top level destination.
- Configured using the builder to generate homescreen button and multiple destinations using the builder.
- Also need to override onSupportNavigateUp() to handle navigation.
Declaring menu
- Create menus with step 1: define bottom navigation menu, step 2 add BottomNavigationView to layout, step 3 setup BottomNavigationView with step 4 Create a fragment for bottom navigation.
- The navigation drawer is used in Android applications for several reasons. First, it provides a consistent and familiar way for users to navigate between different sections of an app.
- For each of the menu items for the layout.
ListView
- Displays a vertically-scrollable collection of views optimized to hold potentially thousands of scrollable items.
- Almost all social media apps use listviews such as Instagram, Facebook and Twitter. To do so, set three steps: First, add listview to the layout. Second, create a string array inside strings.xml: Lebanon Syria Egypt KSA, etc. Thirdly, create an adapter such as a resource and set the adapter to set the view.
- This handles listview items clicks and shows them using Toast prompts.
- In a custom listview, each row (item) is actually a mini-layout containing strings, buttons, images, etc.
- Using the BaseAdapter makes this easier to implement. To do so, make Java class implement the constructor: getCount(), getItem(), getItemId() and getView().
Custom Listview
- Steps 1:Add listview to layout 2: make layout in resource folder for rows 3: Java class that extends BaseAdaper.
Alert DIalogs
- Creates a new class that extends DialogFragment with a builder that contains icon, title, message etc.
- RecyclerView easier to display data RecyclerView recycles those individual elements to improve performance to reduce power consummation. 2. to-do-Step1: add recycler to the layout. -Step-2: mini layout recycler 3, Java class with recycler view adapter.
- App permissions protect user privacy by restricting access to restricted data and actions.
Installation
- Includes normal and signature permissions. normal-permissions present very little risk to the users- privacy and the operation of other apps . 4.Runtime permissions-
Permission Declaration & Request
- Declared in the app-s manifest- runtime checked and requested only from the user -The request is to check to see if the app is already granted a method.
Edit Texts
- Used for entering the text to using keyboard providing choices checkbox. How input control works: 1.use EditText 2. Use seek bar 3.Check box and radio buttons 4.toggle button and switches for each of the items.
Radio Buttons
- Combine radio button elements to radio group- user makes only one choice 5Use switch 6.Use spinner- Specified using the EditText. specifying the keyboard return key and customize with to respond and click events.
- There are two ways to click even if there is something wrong, we make it into the frahement sub class that is declared.
Toggle Buttons
- A slider controlled switch is a toggle button that allows a user to change.
Save data locally
- Shared preferences storing primitive data. SQLite database story structured data with complex queries, higher level abstraction of Sqlite over database over service such as Google, shared preference-If you need to save small key values.
- You create shared preference , You can use one of two methods . getSharedPreferences() getPreferences() for multiple files if you use activity file with default activities. More files using String name file .just the one file access . Data to share to load is optional contains. We load the from optional. If something is contained we load it using different commands. Room peristence Mobile Application development Room Persistence * It is used to save structured data locally.
- Caching network data locally so apps can work offline. * It provides.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.