android - Cursor adapter and sqlite example -


Hello, I am looking for a sample code in which the cursor adapter is used with the squid?

Really Simple Example

Here's a very simple but very effective example. Once you have the basics you can turn it off easily.

There are two main parts to use with Cursor Adapter with SQLite:

  1. From the database select the appropriate cursor < / Strong>.

  2. Create a custom cursor adapter that view the data and pairs from Cursor data From you want to represent the data.

    1 Create a proper cursor from the database.

    In your activity:

      SQLiteOpenHelper sqLiteOpenHelper = new SQLiteOpenHelper (reference, DATABASE_NAME, null, DATABASE_VERSION); SQLiteDatabase sqLiteDatabase = sqLiteOpenHelper.getReadableDatabase (); String query = "SELECT customers ORDER BY company_name ASC"; // not trailing ';' Cursor cursor = sqliteDatabase.rawQuery (query, empty); Client Kaiser Adapter Adapter = New Client Kaiser Adapter (This, R.Ligh Out.clans_writeover_URO, cursor, 0); This.setListAdapter (adapter);   

    Create 2 custom cursor adapter

    Note: Expands from ResourceCursorAdapter that you are using XML to create your own ideas. Public Class Client Kaiser Adapter Resource Kaiser Adapter {Public Client Kaiser Adapter (Reference Reference, Intake Layout, Cursor Cursor, Int Flag) Enhances {super (context, layout, cursor, flags); } @ Override Public Zero Bind View (see View, Reference Reference, Cursor Cursor) {TextView name = (TextView) view.findViewById (R.id.name); Name.setText (cursor.getString (cursor.getColumnIndex ("name"))); TextView phone = (text view) view.findViewById (R.id.phone); Phone.setText (cursor.getString (cursor.getColumnIndex ("phone"))); }}

Comments