ListActivity ormlite 问题?

发布于 2024-10-14 22:27:49 字数 242 浏览 3 评论 0原文

当我决定使用时,我编写了相当大量的代码 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味超标? 2024-10-21 22:27:49

不需要扩展OrmLiteBaseActivity。您只需要自己管理更多实用功能。

您最好的选择是在您的活动中创建自己的DatabaseHelper,并管理其中有多少用户,并在使用完毕后将其丢弃。一般来说,这是 OrmLiteBaseActivity 为您提供的实用程序。一种为您管理数据库对象的机制。这只是一个方便。


示例:

private static Dao<Agent, Object> agentDao = null;
public void someMethod() {
    if(agentDao == null){
      helper = (MyDBHelper) OpenHelperManager.getHelper(getContext());
      try {
        agentDao = helper.getAgentDao();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }

我在 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 the OrmLiteBaseActivity gives to you. A mechanism which will manage your database objects for you. It's just a convenience.


Example:

private static Dao<Agent, Object> agentDao = null;
public void someMethod() {
    if(agentDao == null){
      helper = (MyDBHelper) OpenHelperManager.getHelper(getContext());
      try {
        agentDao = helper.getAgentDao();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }

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.

掌心的温暖 2024-10-21 22:27:49

[@Nick 的回答很好,但我想我应该添加更多信息。 ]

ORMLite 缺少 4.10 版本中添加的 OrmLiteBaseListActivity 类 - 对于错过的情况深表歉意。同时,您可以通过复制 OrmLiteBaseTabActivity 类并将其从 TabActivity 扩展为 ListActivity 的类,轻松创建自己的此类版本。 。然后更改所有列表活动类以扩展这个新类。一旦 4.10 发布,您就可以返回并删除该课程。

例如:

public abstract class OrmLiteBaseListActivity<H extends OrmLiteSqliteOpenHelper>
    extends ListActivity {
    // insert contents of the OrmLiteBaseTabActivity class here
}

[ @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 the OrmLiteBaseTabActivity class changing the class that it extends from TabActivity to ListActivity. 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:

public abstract class OrmLiteBaseListActivity<H extends OrmLiteSqliteOpenHelper>
    extends ListActivity {
    // insert contents of the OrmLiteBaseTabActivity class here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文