Key Points:
1. Use Simplecursoradapter to display Android database information on the ListView
New Simplecursoradapter (thisnullnewnewint[]{r.id.tvname, r.id.tvsex});
2. Press and hold the ListView popup dialog box to delete the information. Incidentally learned the Alertdialog.
Getlistview (). Setonitemlongclicklistener (Listviewitemlongclicklistener); PrivateOnitemlongclicklistener Listviewitemlongclicklistener =NewOnitemlongclicklistener () {@Override Public BooleanOnitemlongclick (adapterview<?>Parent, view view,Final intPositionLongID) {NewAlertdialog.builder (helloworldactivity. This). Settitle ("Title"). Setmessage ("is sure to CANCEL the this ITEM?"). Setnegativebutton ("Cancel",NULL). Setpositivebutton ("Yes",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Cursor C=adapter.getcursor (); C.movetoposition (position); intItemId = C.getint (C.getcolumnindex ("_id")); Dbwrite.delete ("User", "_id=?",NewString[]{itemid+ ""}); //contentvalues CV = new Contentvalues ();//cv.put ("name", "Zp-better");//dbwrite.update ("User", CV, "_id=", New String[]{itemid+ ""});Refreshlistview (); }}). Show (); return true; } };
3. Learn the "additions and deletions" in the Android database.
Demo Download: http://download.csdn.net/detail/z245527922/9492621
Android Database information is displayed on the ListView