3

I have an android app using fragments and a content provider to access my local sqlite database. The Listviews often depend on several database queries such that their display is based on the query results. Assuming I have three cursorloaders, how do I ensure loader 1 and 2 have both completed before running loader 3?

4

1 回答 1

1

跟踪在计数器 ( protected int loadersToRun,loadersCompleted=0;) 中启动的每个加载器,并onLoadFinished调用它们的每个函数

public void checkLoadersFinished(){
    loadersCompleted++
    if(loadersCompleted==loadersToRun){
        //Start loader 3
        loadersCompleted=0;
    }
}

如果您需要使事情动态地工作,可以通过在onLoadFinishedand have that run中使用一组加载程序 ID 的默认情况来完成checkLoadersFinished。我们使用 Treeset 为每个加载器生成一个唯一 ID,以跟踪它们并在完成时将它们删除。

于 2012-07-10T20:20:13.280 回答