Well, I never figured it out, but while I was waiting I ended up doing it in a cleaner way and got around my issues.
How long until I'm no longer a moderated noob??? On Dec 10, 12:04 pm, filbert <[email protected]> wrote: > I'm trying to customize the sample notepad app. I want to add items > automatically from another source (an array, a web service, whatever, > it's hard coded right now) instead of having the user enter them. > After the item is added to the db (via the menu), I want the item > details to be displayed. > > Right now, the item is successfully added to the list, but I just get > a blank screen. If I hit back, the item appears in the list and if I > click on the item in the list, I can see the details without a > problem. > > The code for displaying the details after adding a new item is nearly > identical to just displaying the details alone (except for the method > to actually add it to the database). Both are using the same layout > XML (maybe that's a problem?) so I'm not sure where the breakdown is. > Maybe I'm missing some understanding of the XML UI... > > The only thing I can tell that is really different is that the rowId > is automatically added to the Intent extras when clicking on the list > item, but not when choosing to add a new item from the menu (since the > rowId isn't known yet). I tried adding the rowId into the Intent > extras, but that doesn't seem to make a difference. > > I tried forwarding to the View activity after adding to the DB, which > worked, but then I had issues with the back button and figured I'd go > with this simpler (though redundant) strategy until I can figure out > what I'm doing wrong. > > Any thoughts? > > Here is the relevant calling code from the main class:. It should > look a lot like the tutorial... > -------------------------------------------------------------------------------------------- > @Override > public boolean onMenuItemSelected(int featureId, MenuItem item) { > switch(item.getItemId()) { > case REFRESH_ID: > refreshVerse(); > return true; > } > > return super.onMenuItemSelected(featureId, item); > } > > private void refreshVerse() { > Intent i = new Intent(this, VerseRefresh.class); > startActivityForResult(i, ACTIVITY_REFRESH); > } > > @Override > protected void onListItemClick(ListView l, View v, int position, > long id) { > super.onListItemClick(l, v, position, id); > Intent i = new Intent(this, VerseView.class); > i.putExtra(VerseDbAdapter.KEY_ROWID, id); > startActivityForResult(i, ACTIVITY_VIEW); > } > > -------------------------------------------------------------------------------------------- > And here is my Add item class (which I call refresh): > -------------------------------------------------------------------------------------------- > public class VerseRefresh extends Activity { > > private VerseDbAdapter mDbHelper; > private Long mRowId; > private TextView mVerseDate; > private TextView mVerseNumber; > private TextView mVerseText; > > @Override > protected void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > mDbHelper = new VerseDbAdapter(this); > mDbHelper.open(); > > setContentView(R.layout.verse_details); > > mVerseDate = (TextView) findViewById(R.id.verseDate); > mVerseNumber = (TextView) findViewById(R.id.verseNumber); > mVerseText = (TextView) findViewById(R.id.verseText); > > // since this is a new row, there will not be any id in the > savedInstanceState. > //mRowId = savedInstanceState != null ? > savedInstanceState.getLong > (VerseDbAdapter.KEY_ROWID) : null; > //if (mRowId == null) { > // Bundle extras = getIntent().getExtras(); > // mRowId = extras != null ? extras.getLong > (VerseDbAdapter.KEY_ROWID) : null; > //} > getVerse(); > > Intent i = getIntent(); > i.putExtra(VerseDbAdapter.KEY_ROWID, mRowId); > > populateFields(); > > } > > @Override > protected void onPause() { > super.onPause(); > // not needed > //saveState(); > } > > @Override > protected void onResume() { > super.onResume(); > populateFields(); > } > > @Override > protected void onSaveInstanceState(Bundle outState) { > super.onSaveInstanceState(outState); > outState.putLong(VerseDbAdapter.KEY_ROWID, mRowId); > } > > private void populateFields() { > if (mRowId != null) { > Cursor note = mDbHelper.fetchVerse(mRowId); > startManagingCursor(note); > > mVerseDate.setText(note.getString(note.getColumnIndexOrThrow > (VerseDbAdapter.KEY_VERSE_DATE))); > > mVerseNumber.setText(note.getString(note.getColumnIndexOrThrow > (VerseDbAdapter.KEY_VERSE_NUMBER))); > > mVerseText.setText(note.getString(note.getColumnIndexOrThrow > (VerseDbAdapter.KEY_VERSE_TEXT))); > } > } > > private void getVerse() { > System.out.println("NEED TO CALL WEB SERVICE TO GET VALUES"); > // TODO call web service > String verseDate = "12/10/2008"; > String verseNumber = "123"; > String verseText = "Test text 1"; > > mVerseDate = new TextView(this); > mVerseNumber = new TextView(this); > mVerseText = new TextView(this); > mVerseDate.setText(verseDate); > mVerseNumber.setText(verseNumber); > mVerseText.setText(verseText); > > if (mRowId == null) { > long id = mDbHelper.createVerse(verseDate, > verseNumber, verseText); > if (id > 0) { > mRowId = id; > } > } > else { > System.out.println("NO ID. THIS SHOULDN'T HAPPEN > UNLESS THERE IS A > DB ERROR"); > // TODO don't need this anymore? > //mDbHelper.updateVerse(mRowId, verseDate, > verseNumber); > } > > } > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

