This post is still a work-in-progress.

Table Of Contents

  • Google Maps
  • Common Intent
  • Create Menu on Action Bar
  • Working with strings.xml
  • Create Scroll List
  • Create a URI
  • UI
  • Data Binding


  • FrameLayout: Used to display only one item
  • RelativeLayout: Enables you to decide the relation between the different views. i.e, The textbox should be left to the ImageView…
  • ConstraintLayout: uses constraints to place views – efficient instead of using recursive layouts. notice the layout_constraintLeft_...


Data Binding

Enable Data Binding in your application

in the module build.gradle file, under the Android tag, enable the binding as follows:

android {
    dataBinding.enabled = true;

Use <layout> as the root element of the layout activity

in our example, it is main_activity.xml. Don’t forget to move the xmlns attributes to the root element:

<layout xmlns:app=""

Create a data binding instance called mBinding of type ActivityMainBinding at​​​ (this could be any java file)

ActivityMainBinding mBinding;

Set the Content View using DataBindingUtil to the activity_main layout

DataBindUtil.setContentView replaces our normal call of setContent view.
DataBindingUtil also created our ActivityMainBinding that we will eventually use to
display all of our data.

 mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);

Load a BoardingPassInfo object with fake data using FakeDataUtils

BoardingPassInfo fakeBoardingInfo = FakeDataUtils.generateFakeBoardingPassInfo();

Call displayBoardingPassInfo and pass the fake BoardingInfo instance

    private void displayBoardingPassInfo(BoardingPassInfo info) {

        // COMPLETED (6) Use mBinding to set the Text in all the textViews using the data in info

Activity LifeCycle


Google Maps

Ref here

Common Intents

Common intent is used to share data with other apps via a url.

private void showMap(Uri geoLocation) {
     * Again, we create an Intent with the action, ACTION_VIEW because we want to VIEW the
     * contents of this Uri.
    Intent intent = new Intent(Intent.ACTION_VIEW);

     * Using setData to set the Uri of this Intent has the exact same affect as passing it in
     * the Intent's constructor. This is simply an alternate way of doing this.
    if (intent.resolveActivity(getPackageManager()) != null) {

Ref here


Create Menu on Action Bar

1. Right click the resource directory(res) -> New -> Android Resource Directory


2. In the resource drop list, select menu


3. Right-click the generated menu folder under res, and then New->Menu Resource File

4. Fill Menu with items


5. Override menu methods: In the activity java file, override the next methods:

public boolean onCreateOptionsMenu(Menu menu) {
// COMPLETED (9) Within onCreateOptionsMenu, use getMenuInflater().inflate to inflate the menu
getMenuInflater().inflate(, menu);
// COMPLETED (10) Return true to display your menu
return true;

public boolean onOptionsItemSelected(MenuItem item) {
int itemThatWasClickedId = item.getItemId();
if (itemThatWasClickedId == {
Context context = MainActivity.this;
String textToShow = "Search clicked";
Toast.makeText(context, textToShow, Toast.LENGTH_SHORT).show();
return true;
return super.onOptionsItemSelected(item);

6. Toast: On line 7, use the toast to get the next feature:


Working with strings.xml

you can get a String saved in res -> values -> strings.xml by calling the getString method.

String myString = getString(;


Create Scroll List

add the next to the activity layout xml:

android:textSize="20sp" />

view raw


hosted with ❤ by GitHub

then fill the list as follows:

* Iterate through the array and append the Strings to the TextView. The reason why we add
* the "\n\n\n" after the String is to give visual separation between each String in the
* TextView. Later, we'll learn about a better way to display lists of data.
for (String toyName : toyNames) {
mToysListTextView.append(toyName + "\n\n\n");

Create a URI

To create a well-formed Uri without having to worry about the particular uri components, use the Uri Builder

Uri builtUri = Uri.parse(BASE_URL).buildUpon()
// add various params
.appendQueryParameter(PARAM_QUERY, githubSearchQuery)
.appendQueryParameter(PARAM_SORT, sortBy)
// build the uri
// Convert the Uri to a URL:
URL url = null;
try {
url = new URL(builtUri.toString());
} catch (MalformedURLException e) {
return url;

view raw

hosted with ❤ by GitHub