Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is Activity sample code:</p> <pre><code>public class MainActivity extends Activity { ListView listView; public static final String fields[] = { DatabaseSetup.colName }; Cursor cursor; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.managecontacts); listView = (ListView) findViewById(R.id.lstContacts); DatabaseSetup.init(this); for (Integer i = 0; i &lt; 120; ++i) { DatabaseSetup.createEntry("Name " + i, "Mail " + i, "Phone1 " + i, "Phone2 " + i, "Address " + i, "Notes " + i); } } @Override protected void onPause() { listView.setAdapter(null); cursor.close(); DatabaseSetup.deactivate(); super.onPause(); } @Override protected void onResume() { super.onResume(); DatabaseSetup.init(this); cursor = DatabaseSetup.getContactNames(); SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, fields, new int[] { R.id.item_text }); listView.setAdapter(adapter); } } </code></pre> <p>Here is DatabaseSetup sample code:</p> <pre><code>/* * usage: * DatabaseSetup.init(egActivityOrContext); * DatabaseSetup.createEntry() or DatabaseSetup.getContactNames() or DatabaseSetup.getDb() * DatabaseSetup.deactivate() then job done */ class DatabaseSetup extends SQLiteOpenHelper { static DatabaseSetup instance = null; static SQLiteDatabase db = null; public static void init(Context context) { if (null == instance) { instance = new DatabaseSetup(context); } } public static SQLiteDatabase getDb() { if (null == db) { db = instance.getWritableDatabase(); } return db; } public static void deactivate() { if (null != db &amp;&amp; db.isOpen()) { db.close(); } db = null; instance = null; } public static long createEntry(String name, String mail, String phone1, String phone2, String address, String notes) { ContentValues cv = new ContentValues(); cv.put(colName, name); cv.put(colMail, mail); cv.put(colPhone1, phone1); cv.put(colPhone2, phone2); cv.put(colAddress, address); cv.put(colNotes, notes); return getDb().insert(contactsTable, null, cv); } public static Cursor getContactNames() { // TODO Auto-generated method stub String[] columns = new String[] { "_id", colName }; return getDb().query(contactsTable, columns, null, null, null, null, null); } private DatabaseSetup(Context context) { super(context, dbName, null, dbVersion); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL("CREATE TABLE IF NOT EXISTS " + contactsTable + " (_id integer primary key autoincrement, " + colName + " TEXT NOT NULL, " + colMail + " TEXT NOT NULL, " + colPhone1 + " TEXT NOT NULL, " + colPhone2 + " TEXT NOT NULL, " + colAddress + " TEXT NOT NULL, " + colNotes + " TEXT NOT NULL)"); db.execSQL("CREATE TABLE IF NOT EXISTS " + templatesTable + " (_id integer primary key autoincrement, " + colSubject + " TEXT NOT NULL, " + colBody + " TEXT NOT NULL)"); db.execSQL("CREATE TABLE IF NOT EXISTS " + tagsTable + " (_id integer primary key autoincrement, " + colTagName + " TEXT NOT NULL, " + colContact + " TEXT NOT NULL)"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + contactsTable); db.execSQL("DROP TABLE IF EXISTS " + templatesTable); db.execSQL("DROP TABLE IF EXISTS " + tagsTable); onCreate(db); } static final String dbName = "DB"; static final int dbVersion = 1; static final String contactsTable = "Contacts"; static final String colName = "Name"; static final String colMail = "Email"; static final String colPhone1 = "Phone1"; static final String colPhone2 = "Phone2"; static final String colAddress = "Address"; static final String colNotes = "Notes"; static final String templatesTable = "Templates"; static final String colSubject = "Subject"; static final String colBody = "Body"; static final String tagsTable = "Tags"; static final String colTagName = "Name"; static final String colContact = "Contact"; } </code></pre> <p>Here is 'res/layout/row.xml'</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/item_text" android:layout_width="match_parent" android:layout_height="wrap_content" /&gt; </code></pre> <p>Hope it helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload