1

具有 10 条记录的多个 Arraylist<>。我用这样的方法限制了最多 10 个结果,但是如何获得下一个 10 个结果等等。

try {
ArrayList<CalanderQueryOutput> results = new ArrayList<CalanderQueryOutput>();

List<?> eventsToday = (List<?>) filter.filter(calendar.getComponents(Component.VEVENT));
CalanderQueryOutput caldavOutput = new CalanderQueryOutput();

for (Iterator<?> i = eventsToday.iterator(); i.hasNext();) {
if(Limit < RsLimit){
    results.add(caldavOutput);  
    Limit++;
    }
      }

 }
4

2 回答 2

3

首先,您需要一些其他数据结构来存储多个数组列表,您可以使用列表列表,如

List<List<CalanderQueryOutput>> resultList = new ArrayList<List<CalanderQueryOutput>>();
List<CalanderQueryOutput> results = new ArrayList<CalanderQueryOutput>();
for (Iterator<?> i = eventsToday.iterator(); i.hasNext();) {
if(Limit < RsLimit){
    results.add(caldavOutput);  
    Limit++;
    }else{
     resultList.add(results);
     Limit = 0;
     results = new ArrayList<CalanderQueryOutput>();
}
      }

}

于 2012-06-05T06:58:42.303 回答
0

我已经修改了适用于带有迭代器的 ArrayList 的代码

 int inc = 0;
 int IOF = Integer.parseInt(ItemOffset);
 inc = IOF;
 int IC = Integer.parseInt(ItemCount);
 int TotalLimit = 0;
 int EventLimit = 0;
 for (int l = 0; l < IC; ++l) {
++IOF;
EventLimit = IOF;
 }

 try {
 ArrayList<CalanderQueryOutput> results = new ArrayList<CalanderQueryOutput>();
 List<?> eventsToday = (List<?>)filter.filter(calendar.getComponents(Component.VEVENT));
 CalanderQueryOutput caldavOutput = new CalanderQueryOutput();

 for (Iterator<?> i = eventsToday.iterator(); i.hasNext();) {
   if (TotalLimit < eventsToday.size()) {
    if (TotalLimit >= inc && TotalLimit <= EventLimit - 1){
       results.add(caldavOutput);
         }
     TotalLimit++;
      }
 }catch (SardineException e){
 }
于 2012-06-08T06:46:24.387 回答