ListActivity 中的 getLoaderManager
我希望在 ListActivity 中实现 Loader,但该活动无法识别 getLoaderManager。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbHelper = new DBHelper(this,DBNAME,FindPackageName(), TABLE_NAME);
sql = dbHelper.getReadableDataBase();
//Log.d("Gaurav","Database Open");
String[] from = new String[]{"word","_id","MyList"};
int[] to = new int[]{R.id.listrow };
simpleCursorLoader = new SimpleCursorLoader(this, TABLE_NAME, from, null, null, null, null, null, null, sql);
//query result will be whole database
//cursor = sql.query(TABLE_NAME, from, null, null, null, null, null);
//startManagingCursor(cursor); //this method is deprecated
//Log.d(TAG,"Cursor Set");
completerOrMyListAdapter = new CompleteOrMyListAdapter(this,
R.layout.completeormylist_adapter, cursor, from, to, dbHelper);
setListAdapter(completerOrMyListAdapter);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
LoaderManager lm = getLoaderManager();
//if (lm.getLoader(0) != null) {
// lm.initLoader(0, null, this);
//}
//getLoaderManager().initLoader(0, null, this);
}
I wish to implement a Loader for in a ListActivity but the activity do not recognize getLoaderManager.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbHelper = new DBHelper(this,DBNAME,FindPackageName(), TABLE_NAME);
sql = dbHelper.getReadableDataBase();
//Log.d("Gaurav","Database Open");
String[] from = new String[]{"word","_id","MyList"};
int[] to = new int[]{R.id.listrow };
simpleCursorLoader = new SimpleCursorLoader(this, TABLE_NAME, from, null, null, null, null, null, null, sql);
//query result will be whole database
//cursor = sql.query(TABLE_NAME, from, null, null, null, null, null);
//startManagingCursor(cursor); //this method is deprecated
//Log.d(TAG,"Cursor Set");
completerOrMyListAdapter = new CompleteOrMyListAdapter(this,
R.layout.completeormylist_adapter, cursor, from, to, dbHelper);
setListAdapter(completerOrMyListAdapter);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
LoaderManager lm = getLoaderManager();
//if (lm.getLoader(0) != null) {
// lm.initLoader(0, null, this);
//}
//getLoaderManager().initLoader(0, null, this);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的应用程序仅在 API 级别 11 或更高版本上运行,请适当设置构建目标,并且该方法将可用。
但是,如果您使用 Android 兼容性库来支持 API 级别 11 之前的加载程序,则无法使用
ListActivity
。您必须继承FragmentActivity
。可以使用ListFragment
,也可以只是使用您自己管理的普通ListView
。If your app will only run on API Level 11 or higher, set your build target appropriately, and the method will be available.
However, if you are using the Android Compatibility Library to have support for loaders before API Level 11, you cannot use
ListActivity
. You have to inherit fromFragmentActivity
. Either use aListFragment
, or just a plainListView
that you manage yourself.我认为
如果您使用 support v4 包,您可能会使用下面的内容
i think you probably use below instead
if you use the support v4 package