Join Chiu-Ki Chan for an in-depth discussion in this video Showing Recipes in MainActivity, part of Effective Android Testing for Mobile Developers.
- [Voiceover] Now that we have created RecipeViewHolder and RecipeAdapter, we are ready to use them in main activity to display the recipes. Last step, we need to hookup the RecyclerView in MainActivity. Go to MainActivity. In the MainActivity, in the function onCreate, we will call FindViewById to get the RecyclerView. RecyclerView and then we'll call RecyclerView equal and then FindViewById R.id.recipes.
Alt + enter to cast it into RecyclerView. After that, we will need to have a RecipeStore so that we can use it in Adapter. RecipeStore, store, equal, new RecipeStore. It takes the context, which is this, the MainActivity and then the string for the directory name, which is recipes. With the store, we can create an adapter. RecipeAdapter, adapter, equal, new RecipeAdapter, store.
To ask the RecyclerView to use this adapter, we are going to call RecylerView.setadapter, adapter. We still have a little bit more work to do because we want to configure the RecyclerView to have fixed sides, meaning that each item has the same width and height. And then also assign a layout manager. We will need to call RecyclerView.setHasFixedSize and set it to true. This is because we are going to have a list and the size is going to be just the width of the screen, so it's not going to change, and this can optimize the RecyclerView rendering.
Finally, call RecyclerView.setLayoutManager and we'll give it a new LinearLayoutManager as the perimeter. LinearLayoutManager takes a context as a perimeter, which is this, the MainActivity. With all that, we can finally run this app. Go to the top, click on the drop down, select app, and then click on the green triangle. Alright, we can see all the recipes.
Next we are going to be adding a activity called RecipeActivity so that when you click on the recipe, we can see the details.
- Why test?
- Local vs. on-device
- Code coverage
- UI testing
- Hermetic environment
- Dependency injection
- Testing with MVP
Skill Level Intermediate
Android App Development: Unit Testingwith James P White2h 58m Intermediate
Android Studio Essential Trainingwith David Gassner3h 41m Beginner
Android App Development: Data Persistence Librarieswith Annyce Davis3h 59m Intermediate
1. Testing Considerations
2. Test as You Go
3. UI Testing
4. Hermetic Environment
5. Robot Pattern
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.