I have this code:
private void saveBoard(){
Card tmp;
int n = cardBoard.length;
for(int i = 0; i < n/2; i++) {
for(int j = 0; j < n/2; j++) {
tmp = cardBoard[i][j];
ContentValues values = new ContentValues();
values.put(Constants.ENTRY_COLUMN_POSITIONX, i);
values.put(Constants.ENTRY_COLUMN_POSITIONY, j);
values.put(Constants.ENTRY_COLUMN_VALUE, tmp.getValue());
}
}
Uri uri = context.getContentResolver().insert(BoardContentProvider.CONTENT_URL, values);
Toast.makeText(context, "New Diary-entry Added", Toast.LENGTH_SHORT).show();
}
I'm following this example code:
public void addDiaryEntry(View v) {
String title = mTitle.getText().toString();
String content = mContent.getText().toString();
if(title.isEmpty()) {
mTitle.setError(getText(R.string.error_empty_title));
} else if(content.isEmpty()) {
mContent.setError(getText(R.string.error_empty_content));
} else {
ContentValues values = new ContentValues();
values.put(Constants.ENTRY_COLUMN_TITLE, title);
values.put(Constants.ENTRY_COLUMN_CONTENT, content);
Calendar currentDate = Calendar.getInstance(); //Get the current date
SimpleDateFormat formatter= new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); //format it as per your requirement
String dateNow = formatter.format(currentDate.getTime());
values.put(Constants.ENTRY_COLUMN_RECORD_DATE, dateNow);
Uri uri = getContentResolver().insert(DiaryContentProvider.CONTENT_URL, values);
Toast.makeText(getBaseContext(), "New Diary-entry Added", Toast.LENGTH_SHORT).show();
goToShowDiaries();
}
}
The main difference is, my class extends from GridLayout, and the class from example code extends AppCompatActivity.
The problem is this line:
Uri uri = context.getContentResolver().insert(BoardContentProvider.CONTENT_URL, values);
It doesn't take values as an argument, it wants an expression. What is the proper way to do this? I want to insert something in a db.
Aucun commentaire:
Enregistrer un commentaire