简体   繁体   English

如何预填充 Android Room 数据库并设置视图以显示数据?

[英]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.我需要设置一个从预设信息中提取的 Room 数据库。 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.以下是 Room 2.2.0 支持的这些新功能的示例。

1) Store the .db file in your assets folder and which is prepopulated using some online tool 1) 将.db文件存储在您的资产文件夹中,并使用一些在线工具预先填充

2) then just load it using below code 2)然后使用下面的代码加载它

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 3) 创建模型或实体以及其他数据库,以便在查询这些数据时处理这些数据

For full room using sample follow this doc对于使用示例的完整房间,请遵循此文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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