2017-06-16 92 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