![]() |
VOOZH | about |
In the 1st part of our SQLite database, we have seen How to Create and Add Data to SQLite Database in Android using Jetpack Compose. In that article, we have added data to our SQLite Database. In this article, we will read all this data from the SQLite database and display this data in our ListView using Jetpack Compose.
Refer to the previous article to know how to create data in SQLite Database: How to Create and Add Data to SQLite Database in Android using Jetpack Compose?
We will be working on the existing application which we have built in our previous article. In that application, we are simply adding the course list part where we can get to see our list of courses. A sample video is given at the end to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language.
To create a new project in the Android Studio, please refer to How to Create a new Project in Android Studio with Jetpack Compose.
Navigate to app > kotlin+java > {package-name}, Right-click on it, New > Kotlin class/file and specify its name as CourseModal and add the below code to it.
CourseModal.kt:
In the previous article mentioned above, we created a Database Handler Class named DBHandler.kt to handle out database operation. In this step, we will update this class by adding a function readCourses() to view our data in a list.
DBHandler.kt:
Navigate to app > kotlin+java > {package-name}, Right click on it, New > Empty Views Activity, name it as ViewCourses and uncheck the Generate Layout file option. Now add below code to it. Comments are added in the code to get to know in detail. In this file, we will create a composable function that contains a lazy column and 4 texts inside the each item of the lazy column to display a list of courses.
ViewCourses.kt:
In this step, we will add an extra button to the MainActivity file to navigate to the view courses screen.
MainActivity.kt: