java - 如何一一数出今天有多少项?

标签 java android notificationmanager

我用它来测试日期是否等于今天的日期。我的项目是从 HTML 解析出来的

while(postIt.hasNext)

它会一直持续下去,直到没有剩下为止。

 if(itemDate.contains(todaysDay)){ 
     System.out.println(i);
     nm = (NotificationManager) this.
             getSystemService(Context.NOTIFICATION_SERVICE);
     CharSequence from = "App";
     CharSequence message = nameItem3 + "Today is the day!";
     PendingIntent contentIntent = PendingIntent.getActivity(
             this, 0, new Intent(this, HtmlparserExample.class), 0);
     Notification notif = new Notification(R.drawable.icon, 
             nameOfItem + "Today is the day!!", System.currentTimeMillis());
     notif.setLatestEventInfo(this, from, message, contentIntent);
     nm.notify(1, notif);
  }

我想要做的是测试是否有多个项目等于今天的日期。 如果是的话我想做点什么。

我如何跟踪今天有多少项目?

我想要发生的是,当检索项目时,如果超过 1 个项目等于今天,则会对其进行测试,它会显示不同的通知。

现在发生的情况是,它正在为与今天日期相同的每个项目显示一条通知,一个接一个。

或者其他可行的方法是我可以为每个人显示一条通知吗?我也能这么做吗?

对比。它会覆盖每一个并显示一个新的吗?

最佳答案

将满足测试的 itemDate 实例存储在数组中,并根据数组的内容,在 while 循环之外通知用户。

编辑

ArrayList<ItemDate> itemDates = new ArrayList<ItemDate>();
while(postIt.hasNext){
    /* Do stuff */
    if(itemDate.contains(todaysDay)){
        itemDates.add(itemDate);
        /* Do stuff, not notifying */
    }
}

/* Notify using instances in itemDates */

关于java - 如何一一数出今天有多少项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7221509/

相关文章:

android - Material Design - 'use the tint 700' 是什么意思?

Android通知,振动但没有声音

android - 在警报管理器中显示通知

android - 是否可以设置通知在 android API 级别 10 或更低级别中显示多长时间?

Java:变量不递增

java - 使用 Java API 获取 Elasticsearch 版本

java - 尝试调用方法时出错 "cannot be applied to given types"

java - 使用内部联接查询运行 count() 时,Room 返回包含一项的列表,而不是空列表

Java - Swing 中的监听器

android - Galaxy 选项卡无法连接到 ADB