Android 开发 - ListView 绑定到我的数据库
我是 Android 开发新手,而且我已经很长时间没有做过 Java 了(很好的开始..)。
我不想做任何花哨的事情 - 然而,我只是想通过 SimpleCursorAdaptor 将 Cursor 绑定到 ListView。
我已经让我的主类扩展了“Activity”,因此大多数示例源代码并不真正适用。他们似乎想扩展 ListActivity。
在第一个应用程序屏幕上,我有一个列表视图,需要显示数据库中的数据。我有一个数据库助手,它会很高兴地返回一个包含数据库值的游标。所以真正的问题是 - 在不扩展 ListActivity 类的情况下 - 我到底该怎么做?
这个问题没有代码,因为它只是世界上最简单的事情,我确信知道自己在做什么的人的一些建议就足够了。另请注意,我尝试在项目中创建一个扩展 ListActivity 的新类并调用它,但我仍然不知道绑定如何、何时或在何处发生。它不允许我在列表视图中使用“setListAdapter()” - 它只允许 setAdapter() 导致崩溃。
任何帮助将不胜感激。
I'm new to Android development and it's been a long time since I've done any Java either (great start..).
I'm not looking to do anything fancy - yet, I'm just looking to bind a Cursor to the ListView - through a SimpleCursorAdaptor.
I've already got my main class extending "Activity" so most of the sample source code doesn't really apply. They seem to want to extend ListActivity instead.
Right on the first app screen, I've got a listview that needs to show the data in my database. I've got a DB helper that will happily return a cursor with the database values in it. So the real question is - without extending the ListActivity class - how on earth do I do it?
There's no code in this question as it's just the simplest thing in the world and I'm sure some advice from someone who knows what they're doing would be sufficient. Note also that I've tried creating a new class in my project that does extend ListActivity and called that but I still don't know how or when or where the binding takes place. It doesn't allow me to use "setListAdapter()" to my listview - it only allows setAdapter() which crashes the thing.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Acitivity 扩展该类,在布局 xml 中使用 id
@+id/blahblah
定义 ListView,然后在 Activity 类中找到 ListView id。使用设置适配器You can extend the class with Acitivity that define ListView in the layout xml with id
@+id/blahblah
, then find the ListView id in the Activity class. Set the Adapter using如果你扩展 Activity 它将是
如果你扩展 ListActivity 它将是
If you extend Activity it will be
If you extended ListActivity the it will be