但是,通过对LoaderManager和CursorLoader的使用进行深入研究,我发现了一个内部类扩展了ListFragment(我想到的Fragment本身的扩展)的this示例,我们创建了一个CursorLoader.一切似乎都可以,除了CursorLoader将Uri作为参数的事实除外.所以这意味着我需要创建一个ContentProvIDer来访问我的数据库.
我必须承认它看起来像一个过度的必须通过所有这一切只是创建一个简单的ListVIEw与数据库的项目.特别是如果我无意将数据库数据提供给其他应用程序,而内容提供商的主要目的就是这样做.
那真的值得吗?
特别是在像我这样的情况下,要获取的内容可能会很小.我正在认真考虑以旧的方式做,你说什么?
解决方法 我写了一个不需要内容提供商的 simple CursorLoader:import androID.content.Context;import androID.database.Cursor;import androID.support.v4.content.AsyncTaskLoader;/** * Used to write apps that run on platforms prior to AndroID 3.0. When running * on AndroID 3.0 or above,this implementation is still used; it does not try * to switch to the framework's implementation. See the framework SDK * documentation for a class overvIEw. * * This was based on the CursorLoader class */public abstract class SimpleCursorLoader extends AsyncTaskLoader<Cursor> { private Cursor mCursor; public SimpleCursorLoader(Context context) { super(context); } /* Runs on a worker thread */ @OverrIDe public abstract Cursor loadInBackground(); /* Runs on the UI thread */ @OverrIDe public voID deliverResult(Cursor cursor) { if (isreset()) { // An async query came in while the loader is stopped if (cursor != null) { cursor.close(); } return; } Cursor oldCursor = mCursor; mCursor = cursor; if (isstarted()) { super.deliverResult(cursor); } if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) { oldCursor.close(); } } /** * Starts an asynchronous load of the contacts List data. When the result is ready the callbacks * will be called on the UI thread. If a prevIoUs load has been completed and is still valID * the result may be passed to the callbacks immediately. * <p/> * Must be called from the UI thread */ @OverrIDe protected voID onStartLoading() { if (mCursor != null) { deliverResult(mCursor); } if (takeContentChanged() || mCursor == null) { forceLoad(); } } /** * Must be called from the UI thread */ @OverrIDe protected voID onStopLoading() { // Attempt to cancel the current load task if possible. cancelLoad(); } @OverrIDe public voID onCanceled(Cursor cursor) { if (cursor != null && !cursor.isClosed()) { cursor.close(); } } @OverrIDe protected voID onreset() { super.onreset(); // Ensure the loader is stopped onStopLoading(); if (mCursor != null && !mCursor.isClosed()) { mCursor.close(); } mCursor = null; }}
它只需要AsyncTaskLoader类. AndroID 3.0或更高版本中的一个,或兼容包一起提供的.
总结以上是内存溢出为你收集整理的android – SimpleCursorAdapter的旧构造函数已弃用..真的吗?全部内容,希望文章能够帮你解决android – SimpleCursorAdapter的旧构造函数已弃用..真的吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)