ListActivity ormlite 问题?
当我决定使用时,我编写了相当大量的代码 ORMLite。
阅读文档后,我发现我需要扩展如下:
MyClass extends OrmLiteBaseActivity<DatabaseHelper>
但我已经使用 ListActivity 扩展了它。
是否可以在不扩展 OrmLiteBaseActivity 的情况下做到这一点?
提前Tnx。
I have a rather large amount of code written when I decided to use
ORMLite.
After reading the doc I found that I would need to extend like:
MyClass extends OrmLiteBaseActivity<DatabaseHelper>
but I have already extended it with ListActivity.
Is is possible to do it without extending OrmLiteBaseActivity?
Tnx in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要扩展
OrmLiteBaseActivity
。您只需要自己管理更多实用功能。您最好的选择是在您的活动中创建自己的
DatabaseHelper
,并管理其中有多少用户,并在使用完毕后将其丢弃。一般来说,这是 OrmLiteBaseActivity 为您提供的实用程序。一种为您管理数据库对象的机制。这只是一个方便。示例:
我在 MyDBHelper 类上实现了一个返回 DAO 的方法。查看 ORMLite Android Javadoc 以及更通用的 ORMLite 核心 Javadoc。有很多很好的例子。
It is not a requirement to extend
OrmLiteBaseActivity
. You'll just need to manage more of the utility functions yourself.Your best option would be to create your own
DatabaseHelper
inside your activity and to manage how many users there are of it and to discard it when it is done being used. Generally speaking, this is the utility that theOrmLiteBaseActivity
gives to you. A mechanism which will manage your database objects for you. It's just a convenience.Example:
I had implemented a method to return my DAOs on the class MyDBHelper. Take a look at the ORMLite Android Javadoc as well as the more general ORMLite Core Javadoc. There are lots of good examples out there.
[@Nick 的回答很好,但我想我应该添加更多信息。 ]
ORMLite 缺少 4.10 版本中添加的
OrmLiteBaseListActivity
类 - 对于错过的情况深表歉意。同时,您可以通过复制OrmLiteBaseTabActivity
类并将其从TabActivity
扩展为ListActivity
的类,轻松创建自己的此类版本。 。然后更改所有列表活动类以扩展这个新类。一旦 4.10 发布,您就可以返回并删除该课程。例如:
[ @Nick's answer is fine but I thought I'd add more information. ]
ORMLite is missing a
OrmLiteBaseListActivity
class that was added in version 4.10 -- sorry about the miss. In the meantime, you can easily create your own version of this class by copying theOrmLiteBaseTabActivity
class changing the class that it extends fromTabActivity
toListActivity
. Then change all of your list activity classes to extend this new class. Once 4.10 is out then you can go back and remove the class.For example: