我Cursors在我的应用程序中广泛使用,加载并偶尔从数据库写入信息.我已经看到Honeycomb和兼容包有新的Loader类,旨在帮助以"良好"的方式加载数据.
从本质上讲,这些新类(特别是CursorLoader)比以前的数据管理方法要好得多吗?例如,CursorLoader过度管理有什么好处Cursors?
我使用a ContentProvider处理数据,这显然需要Uris但是如何与initLoader()方法相结合?我必须设置每个Fragments人单独使用装载机吗?并且每个加载器的id需要多么独特,它是在我的应用程序范围内还是仅仅是一个片段?有没有简单的方法简单地传递Uri给CursorLoader来查询我的数据?
我现在所能看到的是,Loaders添加了一个不必要的额外步骤来将我的数据导入我的应用程序,那么有人可以更好地向我解释它们吗?
I have a `cursorLoader` which is working fine.
Run Code Online (Sandbox Code Playgroud)
问题是我不使用它像我应该,我从这些数据加载cursorLoader到arrayLists,然后使用列表.
我发现这个教程,展示了如何使用cursorLoader一个viewPager,但我不明白如何真正做到这一点.
http://tumble.mlcastle.net/post/25875136857/bridging-cursorloaders-and-viewpagers-on-android
我有一个片段,看起来像这样:
public class FirstFragment extends Fragment {
MapView mapView;
GoogleMap map;
// Store instance variables
private String email,about,imagepath,latitude,longitude;
Button getDirections;
// newInstance constructor for creating fragment with arguments
public static FirstFragment newInstance(String email,String about,String imagepath, String latitude, String longitude) {
FirstFragment fragmentFirst = new FirstFragment();
Bundle args = new Bundle();
args.putString("email", email);
args.putString("about", about);
args.putString("imagepath", imagepath);
args.putString("latitude", latitude);
args.putString("longitude", longitude);
fragmentFirst.setArguments(args); …Run Code Online (Sandbox Code Playgroud)