我通过连接getDay,getMonth和getYear成功地以Date格式存储了一些数据,然后将其保存在一个字段中..当我检索它时,它看起来像这样" 15/05/2016" ,我试图使用一些逻辑,如使用查询,但仍然无法工作,是否可以使用查询并创建一个if语句,如果它等于当前日期警报或通知将触发?或以某种其他方式可能......提前感谢..
int qty1=Integer.parseInt(QTY1.getText().toString());
String day = String.valueOf(datePicker.getDayOfMonth());
String getDay=day;
String month = String.valueOf(datePicker.getMonth() + 1);
String getMonth=month;
String year = String.valueOf(datePicker.getYear());
String getYear=year;
int remind=numberPicker.getValue();
String spin=spinner.getSelectedItem().toString();
databaseHelperItems =new DatabaseHelperItems(context);
sqLiteDatabase= databaseHelperItems.getWritableDatabase();
databaseHelperItems.addInformations(descrip,getDay+"
/"+"0"+getMonth+"/"+getYear,remind+"="+spin,qty1+"pcs."
,LocTextView,
sqLiteDatabase);
Toast.makeText(getBaseContext(),"DATA SAVED",Toast.LENGTH_LONG).show();
databaseHelperItems.close();
这是我如何检索它并且工作正常
String today=new SimpleDateFormat("dd/MM/yyyy").format(new Date());
textView.setText(today);
String search_date=textView.getText().toString();
listDataAdapterItems = new ListDataAdapterItems(getApplicationContext(),
R.layout.row_layout);
databaseHelperItems = new DatabaseHelperItems(this);
databaseHelperItems = new DatabaseHelperItems(getApplicationContext());
sqLiteDatabase = databaseHelperItems.getReadableDatabase();
Cursor cursor = databaseHelperItems.getExpiryDate(search_date,
sqLiteDatabase);
listview.setAdapter(listDataAdapterItems);
if (cursor.moveToFirst()) {
do{
String description, month1, qty, remind, locationname;
int myid;
myid = cursor.getInt(0);
description = cursor.getString(1);
month1 = cursor.getString(2);
qty = cursor.getString(3);
remind = cursor.getString(4);
locationname = cursor.getString(5);
DataProviderItems dataProviderItems = new DataProviderItems(String.valueOf(myid) + ".", description, month1, qty, remind, locationname);
listDataAdapterItems.add(dataProviderItems);
}while(cursor.moveToNext());
}
答案 0 :(得分:0)
在我看来,
设置每日闹钟并在接收器类中编写逻辑,从数据库中获取值并检查它是否等于当前日期然后显示通知。
答案 1 :(得分:0)
您应该在SQLite中将“time”存储为“long”类型,然后查询“time”按new SimpleDateFormat("dd/MM/yyyy").format(new Date(time))
显示。