• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android Database Problem

scorpiobuzz

Lurker
Aug 30, 2010
2
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:
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;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.plan_menu);

    Toast.makeText(this, "Choose a day to pick a meal for!", Toast.LENGTH_LONG).show();
    mDbHelper = new NotesDbAdapter(this);
    mDbHelper.open();
    menuDbHelper = new MenuDbAdapter(this);
    menuDbHelper.open();



}

public void mButtonHandler(View target)
{
    switch(target.getId())
    {
    case R.id.monday:
        // Create new intent object and tell it to call the ColorPicker class
        Intent question = new Intent(this, PlanMenuList.class); 
        // Start ColorPicker as a new activity and wait for the result 
        startActivityForResult(question, CHOOSE_MONDAY);
        break;
    case R.id.tuesday:
        // Create new intent object and tell it to call the ColorPicker class
        Intent question1 = new Intent(this, PlanMenuList.class);    
        // Start ColorPicker as a new activity and wait for the result 
        startActivityForResult(question1, CHOOSE_TUESDAY);
        break;
    }
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:
public class PlanMenuList extends ListActivity {

private NotesDbAdapter mDbHelper;
private MenuDbAdapter menuDbHelper;
private List<Data>data;
String menuTitle;
String menuProtein;
String menuBody;
private Long mRowId;




/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.notes_list);
    mDbHelper = new NotesDbAdapter(this);
    menuDbHelper = new MenuDbAdapter(this);
    mDbHelper.open();
    menuDbHelper.open();
    fillData(); 
}

private void fillData() {
    Cursor notesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(notesCursor);

    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[]{NotesDbAdapter.KEY_TITLE};

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[]{R.id.text1};

    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter notes = 
            new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
    setListAdapter(notes);

}

private void populateFields() {
    if (mRowId != null) {
        Cursor note = mDbHelper.fetchNote(mRowId);
        startManagingCursor(note);
        menuTitle=(note.getString(
                note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
        menuProtein=(note.getString(
                note.getColumnIndexOrThrow(NotesDbAdapter.KEY_PROTEIN)));
        menuBody=(note.getString(
                note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
    }
}





protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    mDbHelper.fetchNote(id);
    mRowId = id;
    //populateFields();
    menuDbHelper.createMenu("Monday", menuTitle, menuProtein, menuBody);
    Intent answer = new Intent();
    answer.putExtra("MenuDbAdapter.KEY_ROWID", mRowId);
    setResult(RESULT_OK, answer);
    finish();



}
}
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.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones