0

我用一个表打开了一个 SQLIte 数据库,它有数据列(字符串名称)和 id 列(长 id)。这个属于MainActivity。我想做的下一件事是在同一个表中打开附加列(字符串项目)和(int 价格)。此列将属于 ChildActivity。

我的两个问题是:

  1. 选择哪种方式 - 再打开两列或将项目和价格值存储在一个 String[] 数组中,然后将其放在一列中。应该提到的是,我也需要单独计算的价格。据我了解,放入两个单独的列将更容易获得价格。但是列项目和列价格的 id 会有所不同吗?如果是的话,一切都会变得一团糟。如果我将两者都放在一个 String[] 数组中,是否很容易获取价格(int)值进行计算?

  2. 由于我将通过选择名称并获取它们的 ID 从 MainActivity 访问 ChildActivity,所以当我在现有表中打开新列时,项目的 ID 和价格与我已有的不同?如果不是,那么这是否意味着我必须为项目和价格打开带有新列的新表,并且它们将有自己的 ID?

我是 android 环境和研究 SQLite 的新手,所以如果我的问题看起来很简单,请您为我提供最简单但有效的解决方案并宽容。

先感谢您。

桌子

       MainActivity   =====|====>            ChildActivity
                           |
Column id     Column names | Column (id ?)   Column item  Column (id ?)   Column price
1             A            |                 item_1                       100
2             B            |                 item_2                       300
3             C            |                 item_3                       500
4             D            |                 item_4                       200
5             E            |                 item_5                       100


Another way to do

TABLE

Column id     Column names   Column (id ?)   Column item and price    
1             A                              String[] item_and_price = {"item_1", 100}     
2             B                              String[] item_and_price = {"item_2", 300}     
3             C                              String[] item_and_price = {"item_3", 500}     
4             D                              String[] item_and_price = {"item_1", 200}     
5             E                              String[] item_and_price = {"item_1", 100}     
4

1 回答 1

0

When started to work close with SQLite have found that njzk2 and Yaqub Ahmad are correct. string[] is not convenient to store or to query. ids belong to row and to solve my issue of having item and price chained I have to create new table with column for item and column for price, each entry will have id for both. Hope this information will help for beginners.

于 2012-10-19T05:44:12.957 回答