2

The code below is fetching a date from the date picker but not storing in the database. I want the current date to be replaced by the custom date!!

private DatePickerDialog.OnDateSetListener reservationDate = new 
    DatePickerDialog.OnDateSetListener()
{ 
    @Override
    public void onDateSet(DatePicker view, int year, int month, int day){
        //Button cal=(Button)findViewById(R.id.calendarButton);
        final Calendar c = Calendar.getInstance();
        int curYear = c.get(Calendar.YEAR), curMonth = c.get(Calendar.MONTH)+1, curDay = c.get(Calendar.DAY_OF_MONTH);
        dateG=(Button)findViewById(R.id.btnRem);
        //Picks the selected date, month & year & displays on button
        if((year>curYear)||(year==curYear && month+1>curMonth)||(year==curYear && month+1==curMonth && day>curDay)) {
            dayG = Integer.toString(day);
            monthG = Integer.toString(month + 1);
            yearG = Integer.toString(year);
            dateG.setText(Integer.toString(day) + "/" + Integer.    toString(month + 1) + "/" + Integer.toString(year));
            date=dayG+"/"+monthG+"/"+yearG;
            daOdb.insertDate(date);
            Toast.makeText(getBaseContext(), "Your reminder is set from " + curDay + "-" + curMonth + "-" + curYear + " to " + day + "-" + (month + 1) + "-" + year + ".", Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(getBaseContext(), "Please choose date after " + curDay + "-" + curMonth + "-" + curYear, Toast.LENGTH_SHORT).show();
        }
    }
};

DAOdb is the database where insertDate() is as follows:

public long insertDate(String date)
{
    ContentValues cv = new ContentValues();
    cv.put(DBhelper.COLUMN_DATETIME,date);
    return database.insert(DBhelper.TABLE_NAME, null, cv);
}
SoniaWadji
  • 71
  • 1
  • 5

0 Answers0