whereArgs SQLite database delete
I'm trying to remove a couple of rows in a sqlite database programmatically for android and am wondering what the whereArgs开发者_开发问答 are referring to in this documentation:
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#delete(java.lang.String,%20java.lang.String,%20java.lang.String[])
Can someone give me an example?
whereArgs
are the values to the where clause. When you use the "?" (placeholder) in the second argument (whereClause
), you've to provide the whereArgs
. See this post for details.
Put "=?
" on the end of the second argument (whereClause), like this:
delete(CONTENT_URI, TEXT + "=?", new String [] { text } );
The number of ?
is the number of arguments.
Placeholders ? don't work (buggy) - so you need to construct the whereClause (selection) and send null arguments (selectionArgs)
e.g. To load a dynamic list from using user search text:
mCustomerMenuList = (ListView)findViewById(R.id.customer_menu_list);
mSearchText = (EditText)findViewById(R.id.autoCompleteTextView1);
mSearchText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable t) {
//Reload the query using the search text
ManageMyCustomerMenuList();
mCustomerMenuList.setAdapter(mAdapter);
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// Auto-generated method stub
}
});
and in your ManageMyCustomerMenuList()
query code place something like:
String s = mSearchText.getText().toString().toLowerCase();
String whereClause = Browser.BookmarkColumns.TITLE+" LIKE ?";
String whereArgs [] = new String[] {"%" +s+"%"};
mCustomerCursor = managedQuery(android.provider.Browser.BOOKMARKS_URI,
new String[] {
Browser.BookmarkColumns._ID,
Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL
}, whereClause, whereArgs, mSqlLimit
);
mAdapter = new SimpleCursorAdapter(this, R.layout.row_layout_test,
mCustomerCursor, new String[] {
Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL
}, new int[] {
R.id.test_layout_view1,
R.id.test_layout_view2
}
);
精彩评论