Android Database Problem


Last Updated:

  1. scorpiobuzz

    scorpiobuzz New Member This Topic's Starter

    Joined:
    Aug 30, 2010
    Messages:
    2
    Likes Received:
    0
    Alright, I decided to show some code in this one because I couldn't seem to convey the problem very well otherwise. Here is the calling class
    Code (Text):
    1.  
    2. static final private int CHOOSE_MONDAY = 0; static final private int CHOOSE_TUESDAY = 0; private int ButtonPushed = 0; private NotesDbAdapter mDbHelper; private MenuDbAdapter menuDbHelper; private Long mRowId; String menuTitle; String menuProtein; String menuBody;
    3.  
    4. @Override
    5. protected void onCreate(Bundle savedInstanceState) {
    6.     // TODO Auto-generated method stub
    7.     super.onCreate(savedInstanceState);
    8.  
    9.     setContentView(R.layout.plan_menu);
    10.  
    11.     Toast.makeText(this, "Choose a day to pick a meal for!", Toast.LENGTH_LONG).show();
    12.     mDbHelper = new NotesDbAdapter(this);
    13.     mDbHelper.open();
    14.     menuDbHelper = new MenuDbAdapter(this);
    15.     menuDbHelper.open();
    16.  
    17.  
    18.  
    19. }
    20.  
    21. public void mButtonHandler(View target)
    22. {
    23.     switch(target.getId())
    24.     {
    25.     case R.id.monday:
    26.         // Create new intent object and tell it to call the ColorPicker class
    27.         Intent question = new Intent(this, PlanMenuList.class);
    28.         // Start ColorPicker as a new activity and wait for the result
    29.         startActivityForResult(question, CHOOSE_MONDAY);
    30.         break;
    31.     case R.id.tuesday:
    32.         // Create new intent object and tell it to call the ColorPicker class
    33.         Intent question1 = new Intent(this, PlanMenuList.class);    
    34.         // Start ColorPicker as a new activity and wait for the result
    35.         startActivityForResult(question1, CHOOSE_TUESDAY);
    36.         break;
    37.     }
    38.  
    And then this is the called class where I am trying to copy in the user's selection to the new database and then send back the id to the calling class.
    Code (Text):
    1.  
    2. public class PlanMenuList extends ListActivity {
    3.  
    4. private NotesDbAdapter mDbHelper;
    5. private MenuDbAdapter menuDbHelper;
    6. private List<Data>data;
    7. String menuTitle;
    8. String menuProtein;
    9. String menuBody;
    10. private Long mRowId;
    11.  
    12.  
    13.  
    14.  
    15. /** Called when the activity is first created. */
    16. @Override
    17. public void onCreate(Bundle savedInstanceState) {
    18.     super.onCreate(savedInstanceState);
    19.     setContentView(R.layout.notes_list);
    20.     mDbHelper = new NotesDbAdapter(this);
    21.     menuDbHelper = new MenuDbAdapter(this);
    22.     mDbHelper.open();
    23.     menuDbHelper.open();
    24.     fillData();
    25. }
    26.  
    27. private void fillData() {
    28.     Cursor notesCursor = mDbHelper.fetchAllNotes();
    29.     startManagingCursor(notesCursor);
    30.  
    31.     // Create an array to specify the fields we want to display in the list (only TITLE)
    32.     String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
    33.  
    34.     // and an array of the fields we want to bind those fields to (in this case just text1)
    35.     int[] to = new int[]{R.id.text1};
    36.  
    37.     // Now create a simple cursor adapter and set it to display
    38.     SimpleCursorAdapter notes =
    39.             new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
    40.     setListAdapter(notes);
    41.  
    42. }
    43.  
    44. private void populateFields() {
    45.     if (mRowId != null) {
    46.         Cursor note = mDbHelper.fetchNote(mRowId);
    47.         startManagingCursor(note);
    48.         menuTitle=(note.getString(
    49.                 note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
    50.         menuProtein=(note.getString(
    51.                 note.getColumnIndexOrThrow(NotesDbAdapter.KEY_PROTEIN)));
    52.         menuBody=(note.getString(
    53.                 note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
    54.     }
    55. }
    56.  
    57.  
    58.  
    59.  
    60.  
    61. protected void onListItemClick(ListView l, View v, int position, long id) {
    62.     super.onListItemClick(l, v, position, id);
    63.     mDbHelper.fetchNote(id);
    64.     mRowId = id;
    65.     //populateFields();
    66.     menuDbHelper.createMenu("Monday", menuTitle, menuProtein, menuBody);
    67.     Intent answer = new Intent();
    68.     answer.putExtra("MenuDbAdapter.KEY_ROWID", mRowId);
    69.     setResult(RESULT_OK, answer);
    70.     finish();
    71.  
    72.  
    73.  
    74. }
    75. }
    76.  
    I have been messing around with this thing for days and can't seem to get it to do what I want - any help would be appreciated.
     

    Advertisement
  2. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    What exactly is the problem you are experiencing? I doubt any of us are wiling to look through all of your code and hunt for any problem(s) we can find... Give us some idea of what we are looking for so we can better help you.
     

Share This Page

Loading...