2013-10-06 43 views
0

我在我的應用程序中有一個「客戶信息」表單。我需要填寫在此表格中的數據保存到保存在SD卡上的「交易記錄」文件中。這將成爲此應用已完成的交易的主要列表。 如何將這些數據保存到不斷增長的記錄中?如何將表單數據保存到SD卡上的數據庫?

下面是表格的一個例子。

Name: Sue 
License: D1234567890 
Address: 742 Evergreen Terrace 
State: XY 
Phone: 111-222-3344 

我需要把它保存在某種增長的數據庫的...

| transaction | name | license  | address    | state | phone 
--------------------------------------------------------------------------------------- 
| 4322   | joe  | D4657373888 | 2200 sudderthe road |WZ  | 9543939124 
| 4323   | kim  | D0987655432 | 1st elbow street  |KM  | 5551234444 
| 4324   | sue  | D1234567890 | 742 evergreen terrace |XY  | 1112223344 

這個數據庫將被訪問和應用程序的幾個不同地區的編輯。所以一旦我弄明白了,我可以爲整個應用程序完成很多工作。

最後,我必須得到應用此交易記錄上傳到我們的網站。我採取這一關,當談到......

我使用「下一步」按鈕,這個代碼的onClick:

String custname = name.getText().toString(); 
String custlicense = license.getText().toString(); 
String custstate = state.getText().toString(); 
String custaddress = address.getText().toString(); 
String custcity = city.getText().toString(); 
String custzip = zip.getText().toString(); 
String custphone = phone.getText().toString(); 
String custemail = email.getText().toString(); 
String custdriver = driver.getText().toString(); 

所以我想我只需要弄清楚如何將這些變量保存到某種數據庫。

(我那種用這個地方,幫我弄清楚它是什麼其實我需要做的......這樣我寫這個即時通訊開始回答我的問題:P)

+0

爲什麼你不能爲你的應用使用sqlite數據庫? – eddiecubed

+0

你知道了嗎? –

回答

0

使用SqlLite,又名類SQLiteDatabase。你將所有的CRUD方法放在SQLiteOpenHelper的子類中。這裏也有一些設置工作要做,但最終寫行到數據庫中,你需要如下代碼:

ContentValues values = new ContentValues(); 
values.put ("custname", custname); 
values.put ("cuslicense", custlicense); 
... 
getWritableDatabase().insertOrThrow ("CustomerInformation", null, values); 
+0

如果這個答案有幫助,請upvote。如果你覺得這是正確的答案,那麼檢查它。這將鼓勵人們回答未來的問題:) –

0

使用/從SD卡創建SQLiteDatabase。請閱讀this以瞭解如何實現這一目標。