LoaderManager with multiple loaders: how to get the right cursorloader

前端 未结 3 1336
南旧
南旧 2020-12-12 10:55

To me it\'s not clear how to get the right cursor if you have multiple Loaders. Lets say you define two different Loader with:

getLoaderManager().initLoader(         


        
3条回答
  •  难免孤独
    2020-12-12 11:22

    If your loaders have nothing in common but the class type of the result (here: Cursor), you're better off creating two separate LoaderCallbacks instances (simply as two inner classes in your Activity/Fragment), each one dedicated to one loader treatment, rather than trying to mix apples with oranges.

    In your case it seems that both the data source and the result treatment are different, which requires you to write the extra boilerplate code to identify the current scenario and dispatch it to the appropriate code block.

提交回复
热议问题