简体   繁体   English

如何一一数数等于今天的物品?

[英]How to count how many items equals Todays Day one by one?

I am using this to test if a date is equal to today's date as in day. 我正在用它来测试日期是否等于当天的日期。 My items are parsed from HTML one 我的项目是从HTML解析的

while(postIt.hasNext)

and it keeps going until there are not anymore left. 一直持续下去,直到没有剩余了。

 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);
  }

What i want to do is test if there are more than one item that equals todays date. 我想做的是测试是否有多个项目等于今天的日期。 If so i want to do something if it is. 如果是这样,我想做点什么。

How would i go about tracking how many items are todays Day? 我将如何跟踪今天有多少物品?

What i want to happen is when the items are retreived they are tested if more than 1 item equals today's day, it shows a different notification. 我想发生的是,当退回物品时,如果今天有超过一件物品经过测试,它们会显示不同的通知。

Whats happening now is that it is displaying a notification for each item that has the same date as todays day, one after the other. 现在发生的事情是,它显示与今天相同日期的每个项目的通知,一个接一个。

Or something else that would work is i could i show a notification for each one? 或者其他可行的方法是我可以为每个人显示通知吗? How could i do that too? 我也该怎么办?

Vs. VS. it overriding each one and showing a new one? 它覆盖每个并显示一个新的?

Store your itemDate instances which satisfy your test in an array, and based on the contents of the array, notify the user outside the while loop. 将满足测试条件的itemDate实例存储在数组中,并根据数组的内容在while循环之外通知用户。

EDIT 编辑

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 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM