How does the delete row functionality work in the Android notepad tutorial? -
i'm working through notepad tutorial, , exercise 2 completes code delete notes. however, i'm confused how works. here's relevant code:
public boolean oncontextitemselected(menuitem item) { switch (item.getitemid()) { case delete_id: adaptercontextmenuinfo info = (adaptercontextmenuinfo) item.getmenuinfo(); mdbhelper.deletenote(info.id); filldata(); return true; } return super.oncontextitemselected(item); } the exercise states: "the id field of [adaptercontextmenuinfo] object tells position of item in listview. pass deletenote() method of our notesdbadapter , note deleted."
looking @ database definition, id fields of newly added rows/notes database auto-generated auto-incrementing number. therefore, if have 4 notes id's 1,2,3,4 (not sure if 0 indexed or not!) , delete 2nd note, shouldn't left ids 1,3,4? means trying delete last note (which 3rd in list, still original 4th index) should instead delete row index=3? or rows auto-reindexed when row gets deleted?
finally, can peek/browse database on phone app?
it seems me made small mistake when writing example's text. if see documentation id field of adaptercontextemenuinfo, states returns the row id of element. provided adapter's getid() method.
and, yes, can read phone's database. connect emulator shell (if you're using emulator) using command command line:
adb -e shell you go application's folder (in /data/data/com.yourpackage). there should databases folder. shell, type sqlite3 <databasefilename>. can supported database operations (select, update, etc). check this page out, has section on sqlite3.
Comments
Post a Comment