2017-02-01 41 views
-1

特殊日期的商店警告对话框我有在日期存储在日期列 日期 2017年1月2日显示SQLite中

我想显示警告对话框,如果当前日期数据库日期01相匹配的数据库文件/ 02/2017年

与编辑短信警告对话框得到的东西输入

我有下面的代码,代码 没有错误,但无法显示警告对话框, 任何一个可以帮助?

Date date = new Date(); 
    DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getBaseContext()); 
//the above code will give the current date 

String dbdate = databaseHelper.inserteddate(); //dbdate stored date from database 

if (dateFormat.equals(dbdate)) // compare current date with db date 
{ 
      final AlertDialog.Builder alert = new AlertDialog.Builder(context); 
      alert.setTitle("new date"); 
      alert.setMessage("enter new date"); 
      final EditText editText = new EditText(context); 
      alert.setView(editText); 

      alert.setPositiveButton("yes", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        String s = editText.getEditableText().toString(); 
       } 
      }); 
      alert.setNegativeButton("no", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 
       } 
      }); 
      AlertDialog alertDialog = alert.create(); 
      alertDialog.show(); 

     } 
+0

'dateFormat.equals(dbdate)'错误,您需要将'dbdate'转换为'Date'对象,然后您可以将它与'other Date'对象进行比较。 –

+0

您可以使用其他方式进行检查 –

回答

0

如果您在检查dbdate和dateFormat时遇到if条件,则会解析为false。他们都是两种不同的类型,当然会失败的比较。

dbdata的类型为String,而dateFormat的类型为DateFormat。我建议将它们转换为可以在比较之前相互比较的类型。