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

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. 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.

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归因
不隶属于 StackOverflow
scroll top