简体   繁体   中英

How do I pre-populate an Android Room database and setup a view to display the data?

I need to setup a Room database that draws from preset information. The data will be displayed in the same format with an example photo for each and every time a new search is submitted the new data will replace the old. Below is an example of what I am trying to accomplish.

在此处输入图片说明

Here is an example of these new features which Room 2.2.0 supports.

1) Store the .db file in your assets folder and which is prepopulated using some online tool

2) then just load it using below code

Room.databaseBuilder(appContext, AppDatabase.class, "Sample.db")
.createFromAsset("database/myapp.db")
.build()

3) Create models or entities and other database set up to handle this data when you query on them

For full room using sample follow this doc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM