Shane Darr
- Forum posts: 3
Jun 27, 2011, 3:16:27 AM via Website
Jun 27, 2011 3:16:27 AM via Website
I am building a mileage tracking app for my personal use at work and am to populate a SQLite table with information about the trips I make. I have 2 spinners that allow me to select my starting and ending locations for a trip. I have a button that says, "Log Trip" and when I click on it, it should do an insert into the table with the information about my trip. Everything is working except for one of the spinners. No matter what I pick for my starting location in my app. The table populates the ending location in both starting and ending columns. For example, if I pick a trip going from locationA to locationB in my database the starting column will say locationB and the ending column will also say locationB.
Here is the code I have. Please help, thanks. ps. Very new to this so sorry if the code is crappy.
Here is the code I have. Please help, thanks. ps. Very new to this so sorry if the code is crappy.
1//When the Log Trip button is pressed, settings are saved to DB
2 final Button logTripBtn = (Button) findViewById(R.id.logTripBTN);
3 logTripBtn.setOnClickListener(new View.OnClickListener() {
4 public void onClick(View v) {
5
6 DatePicker pickdate = (DatePicker) findViewById(R.id.datePicker1);
7 final int monthPicked = pickdate.getMonth();
8 final int dayPicked = pickdate.getDayOfMonth();
9
10 TimePicker pickTime = (TimePicker) findViewById(R.id.timePicker1);
11 final int hourPicked = pickTime.getCurrentHour();
12 final int minutePicked = pickTime.getCurrentMinute();
13
14 final EditText startingMileage = (EditText) findViewById(R.id.beginningMileageET);
15 final String startMiles = startingMileage.getText().toString();
16
17 final EditText endingMileage = (EditText) findViewById(R.id.endingMileageET);
18 final String endMiles = (String) endingMileage.getText().toString();
19
20 EditText tripComments = (EditText) findViewById(R.id.commentsET);
21 final String comment = (String) tripComments.getText().toString();
22
23 //Gets and stores the selected spinner values
24 Spinner originLocationSpinner = (Spinner) findViewById(R.id.originSpinner);
25 Spinner destinationLocationSpinner = (Spinner) findViewById(R.id.destinationSpinner);
26 final String originSpinnerSelected;
27 final String destinationSpinnerSelected;
28 Cursor c1 = (Cursor)(originLocationSpinner.getSelectedItem());
29 Cursor c2 = (Cursor)(destinationLocationSpinner.getSelectedItem());
30 if ((c1 != null) && (c2 != null)) {
31 originSpinnerSelected = c1.getString(c1.getColumnIndex(mDbHelper.LOCATIONS_COLUMN1));
32 destinationSpinnerSelected = c2.getString(c2.getColumnIndex(mDbHelper.LOCATIONS_COLUMN1));
33
34 //Calls method in mileagDbAdapter.java that inserts the trip information into the database
35 mDbHelper.logTripInfo(originSpinnerSelected, destinationSpinnerSelected, startMiles, endMiles, monthPicked, dayPicked, hourPicked, minutePicked, comment);
36
37 }}
38 });
2 final Button logTripBtn = (Button) findViewById(R.id.logTripBTN);
3 logTripBtn.setOnClickListener(new View.OnClickListener() {
4 public void onClick(View v) {
5
6 DatePicker pickdate = (DatePicker) findViewById(R.id.datePicker1);
7 final int monthPicked = pickdate.getMonth();
8 final int dayPicked = pickdate.getDayOfMonth();
9
10 TimePicker pickTime = (TimePicker) findViewById(R.id.timePicker1);
11 final int hourPicked = pickTime.getCurrentHour();
12 final int minutePicked = pickTime.getCurrentMinute();
13
14 final EditText startingMileage = (EditText) findViewById(R.id.beginningMileageET);
15 final String startMiles = startingMileage.getText().toString();
16
17 final EditText endingMileage = (EditText) findViewById(R.id.endingMileageET);
18 final String endMiles = (String) endingMileage.getText().toString();
19
20 EditText tripComments = (EditText) findViewById(R.id.commentsET);
21 final String comment = (String) tripComments.getText().toString();
22
23 //Gets and stores the selected spinner values
24 Spinner originLocationSpinner = (Spinner) findViewById(R.id.originSpinner);
25 Spinner destinationLocationSpinner = (Spinner) findViewById(R.id.destinationSpinner);
26 final String originSpinnerSelected;
27 final String destinationSpinnerSelected;
28 Cursor c1 = (Cursor)(originLocationSpinner.getSelectedItem());
29 Cursor c2 = (Cursor)(destinationLocationSpinner.getSelectedItem());
30 if ((c1 != null) && (c2 != null)) {
31 originSpinnerSelected = c1.getString(c1.getColumnIndex(mDbHelper.LOCATIONS_COLUMN1));
32 destinationSpinnerSelected = c2.getString(c2.getColumnIndex(mDbHelper.LOCATIONS_COLUMN1));
33
34 //Calls method in mileagDbAdapter.java that inserts the trip information into the database
35 mDbHelper.logTripInfo(originSpinnerSelected, destinationSpinnerSelected, startMiles, endMiles, monthPicked, dayPicked, hourPicked, minutePicked, comment);
36
37 }}
38 });
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.