加入Button後,List 無法選擇

情況:加入Button後,按list沒有反應。
解決辦法:XML裡的Button要加入  android:focusable="false"

範例:
  <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="下一題"
        android:id="@+id/buttonNext"
        android:onClick="clickNext"
        android:focusable="false"
        android:layout_alignBottom="@android:id/list"
        android:layout_alignParentBottom="true"/>

[Android] SQLiteDatabase

參考資料:http://developer.android.com/intl/zh-tw/reference/android/database/sqlite/SQLiteDatabase.html

使用SQLiteDatabase需要import android.database.sqlite.SQLiteDatabase

SQLiteDatabase類別用於管理資料庫,可以Create,Delete,執行SQL Command。

常用Method

voidexecSQL(String sql)
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
例如create table,drop table

public void execSQL (String sql)

Added in API level 1
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
It has no means to return any data (such as the number of affected rows). Instead, you're encouraged to use insert(String, String, ContentValues),update(String, ContentValues, String, String[]), et al, when possible.
When using enableWriteAheadLogging(), journal_mode is automatically managed by this class. So, do not set journal_mode using "PRAGMA journal_mode'" statement if your app is using enableWriteAheadLogging()
Parameters
sqlthe SQL statement to be executed. Multiple statements separated by semicolons are not supported.
Throws
SQLExceptionif the SQL string is invalid

Public Methods
voidbeginTransaction()
Begins a transaction in EXCLUSIVE mode.
voidbeginTransactionNonExclusive()
Begins a transaction in IMMEDIATE mode.
voidbeginTransactionWithListener(SQLiteTransactionListener transactionListener)
Begins a transaction in EXCLUSIVE mode.
voidbeginTransactionWithListenerNonExclusive(SQLiteTransactionListener transactionListener)
Begins a transaction in IMMEDIATE mode.
SQLiteStatementcompileStatement(String sql)
Compiles an SQL statement into a reusable pre-compiled statement object.
static SQLiteDatabasecreate(SQLiteDatabase.CursorFactory factory)
Create a memory backed SQLite database.
intdelete(String table, String whereClause, String[] whereArgs)
Convenience method for deleting rows in the database.
static booleandeleteDatabase(File file)
Deletes a database including its journal file and other auxiliary files that may have been created by the database engine.
voiddisableWriteAheadLogging()
This method disables the features enabled by enableWriteAheadLogging().
booleanenableWriteAheadLogging()
This method enables parallel execution of queries from multiple threads on the same database.
voidendTransaction()
End a transaction.
voidexecSQL(String sql)
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
voidexecSQL(String sql, Object[] bindArgs)
Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
static StringfindEditTable(String tables)
Finds the name of the first table, which is editable.
List<Pair<StringString>>getAttachedDbs()
Returns list of full pathnames of all attached databases including the main database by executing 'pragma database_list' on the database.
longgetMaximumSize()
Returns the maximum size the database may grow to.
longgetPageSize()
Returns the current database page size, in bytes.
final StringgetPath()
Gets the path to the database file.
Map<StringString>getSyncedTables()
This method was deprecated in API level 11. This method no longer serves any useful purpose and has been deprecated.
intgetVersion()
Gets the database version.
booleaninTransaction()
Returns true if the current thread has a transaction pending.
longinsert(String table, String nullColumnHack, ContentValues values)
Convenience method for inserting a row into the database.
longinsertOrThrow(String table, String nullColumnHack, ContentValues values)
Convenience method for inserting a row into the database.
longinsertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm)
General method for inserting a row into the database.
booleanisDatabaseIntegrityOk()
Runs 'pragma integrity_check' on the given database (and all the attached databases) and returns true if the given database (and all its attached databases) pass integrity_check, false otherwise.
booleanisDbLockedByCurrentThread()
Returns true if the current thread is holding an active connection to the database.
booleanisDbLockedByOtherThreads()
This method was deprecated in API level 16. Always returns false. Do not use this method.
booleanisOpen()
Returns true if the database is currently open.
booleanisReadOnly()
Returns true if the database is opened as read only.
booleanisWriteAheadLoggingEnabled()
Returns true if write-ahead logging has been enabled for this database.
voidmarkTableSyncable(String table, String foreignKey, String updateTable)
This method was deprecated in API level 11. This method no longer serves any useful purpose and has been deprecated.
voidmarkTableSyncable(String table, String deletedTable)
This method was deprecated in API level 11. This method no longer serves any useful purpose and has been deprecated.
booleanneedUpgrade(int newVersion)
Returns true if the new version code is greater than the current database version.
static SQLiteDatabaseopenDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags, DatabaseErrorHandler errorHandler)
Open the database according to the flags OPEN_READWRITE OPEN_READONLY CREATE_IF_NECESSARY and/or NO_LOCALIZED_COLLATORS.
static SQLiteDatabaseopenDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags)
Open the database according to the flags OPEN_READWRITE OPEN_READONLY CREATE_IF_NECESSARY and/or NO_LOCALIZED_COLLATORS.
static SQLiteDatabaseopenOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)
Equivalent to openDatabase(path, factory, CREATE_IF_NECESSARY, errorHandler).
static SQLiteDatabaseopenOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory)
Equivalent to openDatabase(path, factory, CREATE_IF_NECESSARY).
static SQLiteDatabaseopenOrCreateDatabase(File file, SQLiteDatabase.CursorFactory factory)
Equivalent to openDatabase(file.getPath(), factory, CREATE_IF_NECESSARY).
Cursorquery(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Query the given table, returning a Cursor over the result set.
Cursorquery(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit, CancellationSignal cancellationSignal)
Query the given URL, returning a Cursor over the result set.
Cursorquery(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
Query the given table, returning a Cursor over the result set.
Cursorquery(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Query the given URL, returning a Cursor over the result set.
CursorqueryWithFactory(SQLiteDatabase.CursorFactory cursorFactory, boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit, CancellationSignal cancellationSignal)
Query the given URL, returning a Cursor over the result set.
CursorqueryWithFactory(SQLiteDatabase.CursorFactory cursorFactory, boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Query the given URL, returning a Cursor over the result set.
CursorrawQuery(String sql, String[] selectionArgs, CancellationSignal cancellationSignal)
Runs the provided SQL and returns a Cursor over the result set.
CursorrawQuery(String sql, String[] selectionArgs)
Runs the provided SQL and returns a Cursor over the result set.
CursorrawQueryWithFactory(SQLiteDatabase.CursorFactory cursorFactory, String sql, String[] selectionArgs, String editTable)
Runs the provided SQL and returns a cursor over the result set.
CursorrawQueryWithFactory(SQLiteDatabase.CursorFactory cursorFactory, String sql, String[] selectionArgs, String editTable, CancellationSignal cancellationSignal)
Runs the provided SQL and returns a cursor over the result set.
static intreleaseMemory()
Attempts to release memory that SQLite holds but does not require to operate properly.
longreplace(String table, String nullColumnHack, ContentValues initialValues)
Convenience method for replacing a row in the database.
longreplaceOrThrow(String table, String nullColumnHack, ContentValues initialValues)
Convenience method for replacing a row in the database.
voidsetForeignKeyConstraintsEnabled(boolean enable)
Sets whether foreign key constraints are enabled for the database.
voidsetLocale(Locale locale)
Sets the locale for this database.
voidsetLockingEnabled(boolean lockingEnabled)
This method was deprecated in API level 16. This method now does nothing. Do not use.
voidsetMaxSqlCacheSize(int cacheSize)
Sets the maximum size of the prepared-statement cache for this database.
longsetMaximumSize(long numBytes)
Sets the maximum size the database will grow to.
voidsetPageSize(long numBytes)
Sets the database page size.
voidsetTransactionSuccessful()
Marks the current transaction as successful.
voidsetVersion(int version)
Sets the database version.
StringtoString()
Returns a string containing a concise, human-readable description of this object.
intupdate(String table, ContentValues values, String whereClause, String[] whereArgs)
Convenience method for updating rows in the database.
intupdateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm)
Convenience method for updating rows in the database.
booleanyieldIfContended()
This method was deprecated in API level 3. if the db is locked more than once (becuase of nested transactions) then the lock will not be yielded. Use yieldIfContendedSafely instead.
booleanyieldIfContendedSafely(long sleepAfterYieldDelay)
Temporarily end the transaction to let other threads run.
booleanyieldIfContendedSafely()
Temporarily end the transaction to let other threads run.
Protected Methods
voidfinalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
voidonAllReferencesReleased()
Called when the last reference to the object was released by a call to releaseReference() or close().



Query範例

public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, StringorderBy, String limit)

Added in API level 1
Query the given table, returning a Cursor over the result set.
Parameters
tableThe table name to compile the query against.
columnsA list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
selectionA filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table.
selectionArgsYou may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
groupByA filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped.
havingA filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used.
orderByHow to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.
limitLimits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.
Returns
  • Cursor object, which is positioned before the first entry. Note that Cursors are not synchronized, see the documentation for more details.
See Also