2017-06-16 61 views
-2

我有一个ArrayList<MediaItem>在媒体项目中有一个名为一个Boolean场IsDownloaded数组列表使用自定义对象重新排序

我想要一个循环,可以通过IsDownloaded从真提起虚假对项目排序。

+0

任何事情之前,请阅读:https://stackoverflow.com/help/how-to-ask –

回答

0

尝试以下

int ff = 0; // First false index 
    CustomObject pf = list.get(0); // photo with false 

for (int i = 0; i < list.size(); i++) 
    { 
    CustomObject p = list.get(i); 
    if (p. IsDownloaded()) 
    { 
     // Replace it with the current photo with false 
     list.set(i, pf); 
     // Put the selected photo in place of the first false photo (and move this index) 
     list.set(ff++, p); 
     // Next photo is the next to swap (might also advance ff up to the next unselected photo) 
     pf = list.get(ff); 
    } 
    } 



for (CustomObject p : list) { 
    println(p.selected + "," + p.index); 
    } 
+0

由于它的工作。 – husen