本文整理汇总了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;
}
}
示例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;
}
示例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);
}
示例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;
}