Database Views With Room for Android

In this Android Room tutorial, you’ll learn how to use the Database Views feature of Room to create pre-packaged SELECT statements. By Harun Wangereka.

Leave a rating/review
Download materials
Save for later
You are currently viewing page 3 of 3 of this article. Click here to view the first page.

Navigating to All Surveys

This is the last step you need to see the views in action.

Navigate to completedsurvey/SurveyCompletedFragment.kt and uncomment the code inside btnViewSurveys. Your final result will look like this:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  super.onViewCreated(view, savedInstanceState)
  btnViewSurveys.setOnClickListener {

Here, you’re simply setting the click listener for the VIEW SURVEYS button and navigating to AllSurveysFragment.

Once you uncomment the code, the IDE will prompt you to import findNavController(). Simply import the required.

Build, run and start a survey, then answer the questions and submit them. Finally, view All Surveys, where you’ll be able to fetch all the data depending on the option you selected on the spinner.

Spinner options in the app
Averagely happy customers list using a Database View
Sad dinner customers not found using a Database View

Congratulations! You’ve finished your experience at The View Restaurant. Hopefully you have had a great meal, seen amazing views and had a chance to learn what DatabaseViews are.

Where to Go From Here?

Download the final project by using the Download Materials button at the top or bottom of the tutorial.

For more information about Room’s features, check out the official documentation from Android.

We hope you enjoyed this Room Database Views tutorial. If you have any questions, comments or awesome modifications to this project app, please join the forum discussion below.