Android database information displayed on the ListView

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.