I'm trying to save the data from a form in SQLite via Content provider but it doesn't work, there is no error shown in Logcat, but when i examine the database by using this :
http://ift.tt/1LENhg8
there i can see that the data is not being saved... This is the code of the button with the ClickListener for saving:
mSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(TextUtils.isEmpty(mdateEditText.getText().toString()) || TextUtils.isEmpty(mValueEditText.getText().toString())){
Toast.makeText(getApplicationContext(), "Date and Value fields can not be empty.", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Form Saved.", Toast.LENGTH_LONG).show();
mdateEditText.setText("");
mValueEditText.setText("");
mcommentaryEditText.setText("");
setResult(RESULT_OK);
}
}
});
here is my code taking the data from the form:
private void saveForm(){
//Retriving selected item from spinners
String time = (String) mTime.getSelectedItem();
String prepost= (String) mPrePost.getSelectedItem();
String others= (String) mOthers.getSelectedItem();
//Toast.makeText(getApplicationContext(), "SAVEFORM: TIME SELECCIONADO: " +time, Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "SAVEFORM: prepost SELECCIONADO: " +prepost, Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "SAVEFORM: OTHER SELECCIONADO: " +others, Toast.LENGTH_LONG).show();
String dateEditText = mdateEditText.getText().toString();
String commentaryEditText = mcommentaryEditText.getText().toString();
String hemoValue = mValueEditText.getText().toString();
//If form is empty then we can't save the form
if(hemoValue.length() == 0 && dateEditText.length() == 0 ){
return;
}
float hemoRealValue = Float.parseFloat(hemoValue);
ContentValues values = new ContentValues();
values.put(FormTable.COLUMN_DATE, dateEditText);
values.put(FormTable.COLUMN_TIME, time);
values.put(FormTable.COLUMN_PREPOST, prepost);
values.put(FormTable.COLUMN_OTHERS,others);
values.put(FormTable.COLUMN_VALUES,hemoRealValue);
values.put(FormTable.COLUMN_COMMENTARY,commentaryEditText);
//
// if(formUri==null){
formUri = getContentResolver().insert(ContentProviderDB.CONTENT_URI,values);
// }else{
// getContentResolver().update(formUri,values,null,null);
// }
and this is the code of the content provider saving the data with insert method:
@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
int uriType = sUriMatcher.match(uri);
SQLiteDatabase db = sqlite.getWritableDatabase();
long id=0;
switch(uriType){
case SINGLE_VALUE:
id=db.insert(FormTable.TABLE_FORM,null,values);
break;
default:
throw new IllegalArgumentException("Unknown Uri: " + uri);
}
getContext().getContentResolver().notifyChange(uri,null);
return Uri.parse(BASE_PATH + "/" + id);
}
I'm doing everything ok, but it is not saving the data, what could be the problem?? very thanks
Aucun commentaire:
Enregistrer un commentaire