If it’s just to run that command you could do what’s in Insert:
public int update(Uri uri, ContentValues contentValues, String selection,
String[] selectionArgs) {
int uriType = sURIMatcher.match(uri);
SQLiteDatabase sqlDB = database.getWritableDatabase();
int rowsUpdated = 0;
rowsUpdated = sqlDB.update(DATABASE_TABLE,
contentValues, selection, selectionArgs);
getContext().getContentResolver().notifyChange(uri,null);
return rowsUpdated;
}
The call to the method should come already with the pointer positioned in the record you want to update. This is done by selecting the URI with a contentResolver().
My function is a saveState, I will post it, it may help you, but I recommend that you better understand how Contentprovider works, because this update you proposed will always update all the records of your table. This is the expected behavior?
private void saveState() {
String categoria = (String)mCategoria.getSelectedItem();
String descricao = (String)mDescricaoText.getText().toString();
String valor = mValorText.getText().toString();
String parcelas = mParcelasText.getText().toString();
String dataInclusao = mDataInclusao.getText().toString();
String dataVencimento = mDataVencimento.getText().toString();
if(descricao.length() == 0 && valor.length() == 0){
return;
}
ContentValues values = new ContentValues();
values.put(LancamentoTable.COLUMN_DESCRICAO, descricao);
values.put(LancamentoTable.COLUMN_VALOR, valor);
values.put(LancamentoTable.COLUMN_PARCELAS, parcelas);
values.put(LancamentoTable.COLUMN_ID_CATEGORIA, categoria);
values.put(LancamentoTable.COLUMN_DATA_INCLUSAO, dataInclusao);
values.put(LancamentoTable.COLUMN_DATA_VENCIMENTO, dataVencimento);
values.put(LancamentoTable.COLUMN_SINAL, (categoria.toString().equals("DEBITO") ? "-1" : "1"));
if(todoUri==null){
todoUri = getContentResolver().insert(SmartBillContentProvider.CONTENT_URI, values);
} else {
getContentResolver().update(todoUri, values, null, null);
}
}
My code is beginner, I have no great experience on Android, so recommend the link below as a good base to work with Sqlite on Android:
http://www.vogella.com/tutorials/AndroidSQLite/article.html
What is your question? Edit your question and paste the code directly. The way you are is very difficult to do any kind of test.
– André Ribeiro
Prefer codes to images!
– Lollipop
Post codes, images are more complicated to analyze
– Julio Borges