Now that we have seen how to create a database and how to create tables, let's learn how to read from a database.
I'll be using Android Studio 3 to write code. You can get started by adding anko-sqlite dependencies to your project and creating a SQLite database with the Requests
table in it by going through and implementing the Using SQLite database in Kotlin recipe in this chapter. By using the form we created in this recipe, add some data to your Requests
table.
Let's take look at the given steps to understand how to read data from the database:
- Now, let's add a button to our existing layout from the first recipe; on clicking, it should retrieve all data from our
Requests
table. Check out the updated code, which is as follows, where I have added a button with a click listener on it:
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MainActivityUI...