Join Chiu-Ki Chan for an in-depth discussion in this video Favorite: OnClickListener, part of Effective Android Testing for Mobile Developers.
- [Instructor] Let's an on-click listener to the title view so that when someone click on it, we will toggle the status from Favorite to Not Favorite and vicey versa. In line 39, right after you set selected for the title view, add an on click listener titleView.setonclicklistener and then new on click listener. Inside the on click function, we will first call toggle to save the state to be the opposite of what is showing.
Boolean result equal favorites dot toggle, and we'll pass the recipe id. Right now, there are red lines under the word recipe. First, alt enter, and make recipe final. After we toggle, we will need to update the UI. So we will do title view dot set selected, and then we'll pass in the result.
Let's run the app. Press the green triangle. Once again, we'll click on chocolate pudding, and this time, we will click on the star to see that it has turned solid. Go back to main activity and click on chocolate pudding again. Yea! It stays solid, meaning that our app has remembered that we indeed like chocolate pudding. We have added the functionality to save favorites to our recipes app. Remember, this is a testing course, so next let's write a test for it.
- 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.