當前位置: 首頁>>代碼示例>>Java>>正文


Java Activity.openOrCreateDatabase方法代碼示例

本文整理匯總了Java中android.app.Activity.openOrCreateDatabase方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.openOrCreateDatabase方法的具體用法?Java Activity.openOrCreateDatabase怎麽用?Java Activity.openOrCreateDatabase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.Activity的用法示例。


在下文中一共展示了Activity.openOrCreateDatabase方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: openMyBookmark

import android.app.Activity; //導入方法依賴的package包/類
public void openMyBookmark(Activity activity)
   {
try
{
    m_db = activity.openOrCreateDatabase(DBNAME, 0, null);
}
catch (SQLiteException e)
{
    m_db = null;
}
   }
 
開發者ID:stytooldex,項目名稱:pius1,代碼行數:12,代碼來源:Bookmark.java

示例2: selectedItem

import android.app.Activity; //導入方法依賴的package包/類
static String selectedItem(Activity activity, String[] who, int where, ArrayList<String> column) {

        //create the notes db
        SQLiteDatabase notesDB = activity.openOrCreateDatabase("notesDB", MODE_PRIVATE, null);

        Cursor notesCursor = notesDB.rawQuery("SELECT * FROM " + who[0], null);

        String selected = "";

        if (notesCursor != null && notesCursor.moveToFirst()) {

            while (!notesCursor.isAfterLast()) {

                //get items at selected position
                selected = column.get(where);
                notesCursor.moveToNext();
            }
            notesCursor.close();
        }

        notesDB.close();

        return selected;
    }
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:25,代碼來源:NotesUtils.java

示例3: deleteNote

import android.app.Activity; //導入方法依賴的package包/類
private static void deleteNote(Activity activity, int pos) {

        SQLiteDatabase notesDB = activity.openOrCreateDatabase("notesDB", MODE_PRIVATE, null);

        String title = NotesUtils.selectedItem(activity, NoteField.TITLES, pos, notesTitles);
        String note = NotesUtils.selectedItem(activity, NoteField.NOTES, pos, notesBodies);
        String date = NotesUtils.selectedItem(activity, NoteField.DATES, pos, notesDates);
        String priority = NotesUtils.selectedItem(activity, NoteField.PRIORITIES, pos, notesPriorities);


        String titlesTable, notesTable, datesTable, prioritiesTable,
                whereClause_title, whereClause_note, whereClause_date, whereClause_priority;

        String[] whereArgs_title, whereArgs_note, whereArgs_date, whereArgs_priority;

        //set the names of the tables
        titlesTable = "titles";
        notesTable = "notes";
        datesTable = "dates";
        prioritiesTable = "priorities";

        //set where clause
        whereClause_title = "title" + "=?";
        whereClause_note = "note" + "=?";
        whereClause_date = "date" + "=?";
        whereClause_priority = "priority" + "=?";

        //set the where arguments
        whereArgs_title = new String[]{title};
        whereArgs_note = new String[]{note};
        whereArgs_date = new String[]{date};
        whereArgs_priority = new String[]{priority};

        //delete 'em all
        notesDB.delete(titlesTable, whereClause_title, whereArgs_title);
        notesDB.delete(notesTable, whereClause_note, whereArgs_note);
        notesDB.delete(datesTable, whereClause_date, whereArgs_date);
        notesDB.delete(prioritiesTable, whereClause_priority, whereArgs_priority);

        //update data arrays and update the recycler view

        //remove all the adapter data
        notesTitles.remove(pos);
        notesBodies.remove(pos);
        notesDates.remove(pos);
        notesPriorities.remove(pos);

        NotesRecyclerViewAdapter notesRecyclerViewAdapter = new NotesRecyclerViewAdapter(activity, notesTitles, notesBodies, notesPriorities, notesDates);

        RecyclerView notesRecyclerView = activity.findViewById(R.id.notesRecyclerView);

        //and update the dynamic list
        //don't move this method above the db deletion method or you'll get javalangindexoutofboundsexception-invalid-index error
        notesRecyclerView.getAdapter().notifyDataSetChanged();

        notesRecyclerView.setAdapter(notesRecyclerViewAdapter);

    }
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:59,代碼來源:NotesRecyclerViewAdapter.java

示例4: initNoteElement

import android.app.Activity; //導入方法依賴的package包/類
static ArrayList<String> initNoteElement(Activity activity, String[] who) {

        //create the notes db
        SQLiteDatabase notesDB = activity.openOrCreateDatabase("notesDB", MODE_PRIVATE, null);

        //create a table called ? with a column called ? where notes titles will be stored
        notesDB.execSQL("CREATE TABLE IF NOT EXISTS " + who[0] + "(id INTEGER PRIMARY KEY AUTOINCREMENT," + who[1] + " varchar);");

        ArrayList<String> selected = new ArrayList<>();

        Cursor notesDBcursor;

        notesDBcursor = notesDB.rawQuery("SELECT * FROM " + who[0], null);

        if (notesDBcursor != null && notesDBcursor.moveToFirst()) {

            while (!notesDBcursor.isAfterLast()) {

                //add items to selected field
                selected.add(notesDBcursor.getString(notesDBcursor.getColumnIndex(who[1])));
                notesDBcursor.moveToNext();
            }
            notesDBcursor.close();
        }

        notesDB.close();

        return selected;
    }
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:30,代碼來源:NotesUtils.java


注:本文中的android.app.Activity.openOrCreateDatabase方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。