我用它来测试日期是否等于今天的日期。我的项目是从 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/