Android tutorial - sqlite android - android app development - android studio - android development tutorial
- SQLite is an open-source relational database i.e. used to perform database operations on android devices such as storing, manipulating or retrieving persistent data from the database.
- It is embedded in android by default. So, there is no need to perform any database setup or administration task.
- Here, we are going to see the example of sqlite to store and fetch the data.
- Data is displayed in the logcat. For displaying data on the spinner or listview, move to the next page.
- SQLiteOpenHelper class provides the functionality to use the SQLite database.
- The android.database.sqlite.SQLiteOpenHelper class is used for database creation and version management.
- For performing any database operation, you have to provide the implementation of onCreate() and onUpgrade() methods of SQLiteOpenHelper class.
Android Sqlite Example:
- In this example, we are adding a label on button click and displaying all the added labels on the spinner.
- As you have seen in the previous example, SQLiteOpenHelper class need to be extended for performing operations on the sqlite.
- We have overridden the onCreate() and onUpgrade() method of SQLiteOpenHelper class in the DatabaseHandler class that provides additional methods to insert and display the labels or data.
Android Sqlite Spinner Example:
- Let's see the simple code to add and display the string content on spinner using sqlite database.
- File: activity_main.xml
- File: MainActivity.java
- File: DatabaseHandler.java