Android Four: Sqllite

Source: Internet
Author: User

1. Extended Class Sqliteopenhelper

Xxsqlitehelper extends Sqliteopenhelper

Public Xxsqlitehelper (Context context,string name,cursorfactory factory,int version) {

Surper (context,name,null,1);

}

OnCreate (Sqlitedatabase db)

Onupgrade (sqlitedatebase db,int newversion,int oldversion)

Cursor c//pointer to query result

C.getstring (C.getcolumindex ("name"))

2. Use

Xxsqlitehelper xx=new Xxsqlitehelper (this);

Sqlitedatabase db=xx.getwritabledatabase ();

Db.insert .....

Db.query ()

Db.close ();

3, Show: Simplecorsoradapter sa=new simplecorsoradapter (this,layout,c,new string[]{"name", "Sex"},new int[]{R.id.iname, R.id.isex});

The requirement table must have a column, _id Integer primary Key AutoIncrement

Refresh the ListView:

Sa.changecorsor (c);

Plug in a mouth: Accessing potentially variable variables in an inner class is not allowed, so it is qualified with the final constant

Android Four: Sqllite

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.