build this app! • How to create different screens for your app • How to build the UI / Layout for each screen • How to show a list of similar items (each item has a movie image, a title, and a description)
build this app! • How to create different screens for your app • How to build the UI / Layout for each screen • How to show a list of similar items (each item has a movie image, a title, and a description) • How to retrieve the information we need to display all this?
of Android Studio and the Android project structure • We’ll also look a deeper look at the main building piece of Android apps : Activities and their Layouts
the user can interact with In Android, a ‘screen’ is called an Activity Activities are where we write Java code to handle logic for user interactions, change what’s on the screen, and a lot more
Provide a direct reference to each of the views within a data item // Used to cache the views within the item layout for fast access public class ViewHolder extends RecyclerView.ViewHolder { } // Usually involves inflating a layout from XML and returning the holder @Override public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } // Involves populating data into the item through holder @Override public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) { } }
Provide a direct reference to each of the views within a data item // Used to cache the views within the item layout for fast access public class ViewHolder extends RecyclerView.ViewHolder { } // Usually involves inflating a layout from XML and returning the holder @Override public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } // Involves populating data into the item through holder @Override public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) { } }
Provide a direct reference to each of the views within a data item // Used to cache the views within the item layout for fast access public class ViewHolder extends RecyclerView.ViewHolder { } // Usually involves inflating a layout from XML and returning the holder @Override public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } // Involves populating data into the item through holder @Override public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) { } }
Provide a direct reference to each of the views within a data item // Used to cache the views within the item layout for fast access public class ViewHolder extends RecyclerView.ViewHolder { public TextView nameTextView; public TextView messageTitleTextView; // We also create a constructor that accepts the entire item row // and does the view lookups to find each subview public ViewHolder(View itemView) { // Stores the itemView in a public final member variable that can be used // to access the context from any ViewHolder instance. super(itemView); nameTextView = (TextView) itemView.findViewById(R.id.name); messageTitleTextView = (TextView) itemView.findViewById(R.id.messageTitle); } } // Usually involves inflating a layout from XML and returning the holder @Override public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } // Involves populating data into the item through holder @Override public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) { } }
Provide a direct reference to each of the views within a data item // Used to cache the views within the item layout for fast access public class ViewHolder extends RecyclerView.ViewHolder { } // Usually involves inflating a layout from XML and returning the holder @Override public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } // Involves populating data into the item through holder @Override public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) { } }
Provide a direct reference to each of the views within a data item // Used to cache the views within the item layout for fast access public class ViewHolder extends RecyclerView.ViewHolder { } // Usually involves inflating a layout from XML and returning the holder @Override public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { Context context = parent.getContext(); LayoutInflater inflater = LayoutInflater.from(context); // Inflate the custom layout View emailItemView = inflater.inflate(R.layout.item_email, parent, false); // Return a new holder instance ViewHolder viewHolder = new ViewHolder(emailItemView); return viewHolder; } // Involves populating data into the item through holder @Override public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) { } }
Provide a direct reference to each of the views within a data item // Used to cache the views within the item layout for fast access public class ViewHolder extends RecyclerView.ViewHolder { } // Usually involves inflating a layout from XML and returning the holder @Override public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } // Involves populating data into the item through holder @Override public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) { } }
Provide a direct reference to each of the views within a data item // Used to cache the views within the item layout for fast access public class ViewHolder extends RecyclerView.ViewHolder { } // Usually involves inflating a layout from XML and returning the holder @Override public ContactsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } // Involves populating data into the item through holder @Override public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) { // Get the data model based on position Email email = emailsToDisplay.get(position); // Set item views based on your views and data model viewHolder.nameTextView.setText(email.getName()); viewHolder.messageTitleTextView.setText(email.getTitle()); } }
ArrayList<Email> emails; @Override protected void onCreate(Bundle savedInstanceState) { // ... // Lookup the recyclerview in activity layout RecyclerView rvEmails = (RecyclerView) findViewById(R.id.rvEmailList); // Call api to get list of emails emails = getEmails(); // Create adapter passing in the sample user data EmailAdapater adapter = new EmailAdapater(emails); // Attach the adapter to the recyclerview to populate items rvEmails.setAdapter(adapter); // Set layout manager to position the items rvEmails.setLayoutManager(new LinearLayoutManager(this)); // That's all! } }
ArrayList<Email> emails; @Override protected void onCreate(Bundle savedInstanceState) { // ... // Lookup the recyclerview in activity layout RecyclerView rvEmails = (RecyclerView) findViewById(R.id.rvEmailList); // Call api to get list of emails emails = getEmails(); // Create adapter passing in the sample user data EmailAdapater adapter = new EmailAdapater(emails); // Attach the adapter to the recyclerview to populate items rvEmails.setAdapter(adapter); // Set layout manager to position the items rvEmails.setLayoutManager(new LinearLayoutManager(this)); // That's all! } }
ArrayList<Email> emails; @Override protected void onCreate(Bundle savedInstanceState) { // ... // Lookup the recyclerview in activity layout RecyclerView rvEmails = (RecyclerView) findViewById(R.id.rvEmailList); // Call api to get list of emails emails = getEmails(); // Create adapter passing in the sample user data EmailAdapater adapter = new EmailAdapater(emails); // Attach the adapter to the recyclerview to populate items rvEmails.setAdapter(adapter); // Set layout manager to position the items rvEmails.setLayoutManager(new LinearLayoutManager(this)); // That's all! } }
ArrayList<Email> emails; @Override protected void onCreate(Bundle savedInstanceState) { // ... // Lookup the recyclerview in activity layout RecyclerView rvEmails = (RecyclerView) findViewById(R.id.rvEmailList); // Call api to get list of emails emails = getEmails(); // Create adapter passing in the sample user data EmailAdapater adapter = new EmailAdapater(emails); // Attach the adapter to the recyclerview to populate items rvEmails.setAdapter(adapter); // Set layout manager to position the items rvEmails.setLayoutManager(new LinearLayoutManager(this)); // That's all! } }
ArrayList<Email> emails; @Override protected void onCreate(Bundle savedInstanceState) { // ... // Lookup the recyclerview in activity layout RecyclerView rvEmails = (RecyclerView) findViewById(R.id.rvEmailList); // Call api to get list of emails emails = getEmails(); // Create adapter passing in the sample user data EmailAdapater adapter = new EmailAdapater(emails); // Attach the adapter to the recyclerview to populate items rvEmails.setAdapter(adapter); // Set layout manager to position the items rvEmails.setLayoutManager(new LinearLayoutManager(this)); // That's all! } }
ArrayList<Email> emails; @Override protected void onCreate(Bundle savedInstanceState) { // ... // Lookup the recyclerview in activity layout RecyclerView rvEmails = (RecyclerView) findViewById(R.id.rvEmailList); // Call api to get list of emails emails = getEmails(); // Create adapter passing in the sample user data EmailAdapater adapter = new EmailAdapater(emails); // Attach the adapter to the recyclerview to populate items rvEmails.setAdapter(adapter); // Set layout manager to position the items rvEmails.setLayoutManager(new LinearLayoutManager(this)); // That's all! } }
currently playing, we need to access data stored on the internet APIs allow us to access all types of different data https://api.themoviedb.org/3/movie/ now_playing?api_key={your_api_key}
"vote_average": 6.6, "title": "Venom", "popularity": 225.576, "poster_path": "\/2uNW4WbgBXL25BAbXGLnLqX71Sw.jpg", "original_language": "en", "original_title": "Venom", "genre_ids": [ 878 ], "backdrop_path": "\/VuukZLgaCrho2Ar8Scl9HtV3yD.jpg", "adult": false, "overview": "When Eddie Brock acquires the powers of a symbiote, he will have to release his alter-ego \"Venom\" to save his life.", "release_date": "2018-10-03" }, { "vote_count": 881, "id": 424694, "video": false, "vote_average": 8.3, "title": "Bohemian Rhapsody", "popularity": 134.625, "poster_path": "\/lHu1wtNaczFPGFDTrjCSzeLPTKN.jpg", "original_language": "en", "original_title": "Bohemian Rhapsody", "genre_ids": [ 18, 10402 ], "backdrop_path": "\/pbXgLEYh8rlG2Km5IGZPnhcnuSz.jpg", "adult": false, "overview": "Singer Freddie Mercury, guitarist Brian May, drummer Roger Taylor and bass guitarist John Deacon take the music world by storm when they form the rock 'n' roll band Queen in 1970. Hit songs become instant classics. When Mercury's increasingly wild lifestyle starts to spiral out of control, Queen soon faces its greatest challenge yet \u2013 finding a way to keep the band together amid the success and excess.", "release_date": "2018-10-24" }, { …
is running on just one thread, also known as the Main Thread, or UI Thread. This means that if start doing one task (ie : making a network call), we cannot start another task (ie: processing user interaction) until the first task finishes.
is running on just one thread, also known as the Main Thread, or UI Thread. This means that if start doing one task (ie : making a network call), we cannot start another task (ie: processing user interaction) until the first task finishes. Since network calls can take a unknown amount of time, we don’t want our app to appear ‘frozen’ or ‘unresponsive’ when we’re waiting for a network call to complete.
requests outside of the app’s Main Thread When we use it to make a network call, we also get access to callback methods that’ll allow us to handle the result of the network call
@Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // this method will get called if the network request succeeds } @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable e) { // this method will get called if the network request fails } });
@Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // this method will get called if the network request succeeds } @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable e) { // this method will get called if the network request fails } });
@Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // this method will get called if the network request succeeds } @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable e) { // this method will get called if the network request fails } });