private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener()
{
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,int selectedMonth, int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;
try
{
db=openOrCreateDatabase("Lecturer",SQLiteDatabase.CREATE_IF_NECESSARY,null);
db.execSQL("Create Table If Not Exists temp (Month INTEGER,Date INTEGER,Year INTEGER,Event TEXT)");
db.execSQL("INSERT INTO temp(Month, Date, Year, Event) VALUES (11,17,2012,'first')");
db.execSQL("INSERT INTO temp(Month, Date, Year, Event) VALUES (10,9,2012,'second')");
Cursor c=db.rawQuery("SELECT * FROM temp",null);
c.moveToFirst();
while(c.isAfterLast() == false)
{
t2=c.getString(0);
// Log.e("",""+t2);
int n = Integer.parseInt(t2);
t3=c.getString(1);
int n1 = Integer.parseInt(t3);
t4=c.getString(2);
int n2 = Integer.parseInt(t4);
t5=c.getString(3);
EditText t=(EditText)findViewById(R.id.editText1);
Log.e("",""+day);
if(day==n&& month==n1&&year==n2)
{
Log.e("",""+t5);
t.setText(t5);
}
else
{
t.setText("No Event");
}
c.moveToNext();
}
c.close();
}
catch(SQLException e)
{
}
// set selected date into textview
tvDisplayDate.setText(new StringBuilder().append(month + 1)
.append("-").append(day).append("-").append(year)
.append(" "));
// set selected date into datepicker also
dpResult.init(year, month, day, null);
}
};
}
在 DB 中存储和获取事件时,我遇到了一些问题并强制关闭。请帮助我提出任何有用的建议……这里我试图将 datepicker 选择的日期与数据库存储的日期进行比较,并显示当天的事件。