Reputation: 1120
I have 4 EditText fields that the user will input data for. I want to be able to save the data to a database internally (on the device).
Here are the declarations (during my onCreate):
String[] debtName = new String[10];
double[] debtAmount = new double[10];
int[] debtRate = new int[10];
double[] debtPayment = new double[10];
int trigger = 0;
Later, I pull the data from the EditTexts (during a ButtonOnClick):
EditText editDebtName = (EditText) findViewById(R.id.dispDebtName);
debtName[trigger] = editDebtName.getText().toString();
EditText editDebtAmount = (EditText) findViewById(R.id.dispDebtAmount);
String debtAmountStr = editDebtAmount.getText().toString();
debtAmount[trigger] = Double.parseDouble(debtAmountStr);
EditText editDebtRate = (EditText) findViewById(R.id.dispDebtRate);
String debtRateStr = editDebtRate.getText().toString();
debtRate[trigger] = Integer.parseInt(debtRateStr);
EditText editDebtPayment = (EditText) findViewById(R.id.dispDebtPayment);
String debtPaymentStr = editDebtPayment.getText().toString();
debtPayment[trigger] = Double.parseDouble(debtPaymentStr);
I'm looking for any simple resources on how to save these pieces of data to a db (preferable without parsing the data anymore).
Upvotes: 3
Views: 178
Reputation: 25267
Without parsing, the data you will recieve will be in the form CharSequence[]
(which later you can transform in to string by toString()
method), and this is recommended only if you are not going to do any arithematic operations with those integers and doubles. But if you want to do, you have to definitely go with parsing these values.
Check this link on developer.android.com: http://developer.android.com/training/basics/data-storage/databases.html
Also check these links for database tutorials:
Upvotes: 1