English 中文(简体)
用静态数据在Android 中弹出 SQLiteDatabase 的 SQLiteDatabase
原标题:Populate an SQLiteDatabase in Android with static data

我有一个包含多个表格的数据库。 这些表格之一( sport) 就是我必须放置一个静态对象列表的位置, 每个对象都有 _id、 名称、 标志和 int。 其它表格将使用 _ id 来做一些查询( 例如从“ tab X” 中选择“ tab_ id=_ id =_id id), 因此它应该更改加班时间( 如果更改的话, 有办法更新所有引用此 _ id 的引用吗? ) 。 我应在哪里设置代码( 我认为这将是 db. develop () 的简单列表), 使其只添加一行( 检查行数是否增长, 添加新行 )? 最多不会有50行 。

最佳回答

我认为我会在 dbHelper 中做一个方法来插入数据, 然后在程序启动时立即调用这个方法。 我在这里做了几个假设... 首先,你将这个静态信息 和应用程序一起发送, 当你想要添加更多信息时, 你将会发送一个新的版本 。

您可以将数据作为文本文件存储到资产文件夹中, 然后在方法中执行批次插入时读取文件 。

如果您设置正确( 使用 < code> InfoteOnfriend 和 < code> CONFLICT_ INGORE < /code> 旗在方法中), 它将只每次添加新行( 如果有的话), 这样您就可以每次程序启动时运行新行, 而不担心重复数据或因限制违反而崩溃 。

如果您只想要它运行一次, 当有附加信息时, 请在文本文件中输入一个版本编号, 并对照上一个( 您可以在共享属性中存储) 来检查该版本的编号 。

<强 > EDIT

使用插入在冲突中的示例:

public long createItem(String yourdata) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(YOUR_COLUMN, yourdata);
    return mDb.insertWithOnConflict(YOUR_TABLE, null, initialValues,
            SQLiteDatabase.CONFLICT_IGNORE);
}

您可以阅读 SQLiteDatabase 类( 包含常数和方法) < a href="http:// developmenter.android.com/ reference/android/ database/ sqlite/ SQLiteDatabase.html" rel=“ no follow” >这里

问题回答

暂无回答


上一篇:
下一篇:


相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签