如何更改从数据库获取的数据?
我使用以下代码从数据库中获取数据:
private void fillData() {
cursor = mDbAdapter.fetchAllSubjects();
startManagingCursor(cursor);
String[] from = new String[] { DatabaseAdapter.KEY_TITLE, DatabaseAdapter.KEY_LECTURER, DatabaseAdapter.KEY_BEGIN };
int[] to = new int[] { R.id.title, R.id.lecturer, R.id.time };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter subjects = new SimpleCursorAdapter(this, R.layout.subject_row, cursor, from, to);
setListAdapter(subjects);
}
现在我的问题是,我想从数据库中添加其他 3 列,并希望获取以下内容:
- "("+DatabaseAdapter.KEY_TYPE+") "+DatabaseAdapter.KEY_TITLE
- DatabaseAdapter.KEY_LECTURER
- 新日期(DatabaseAdapter.KEY_BEGIN)
- 新日期(DatabaseAdapter.KEY_END) -->这两个应该以 dd.MM 的方式位于一个 TextView 中。 HH:mm(这是从 BEGIN 开始的)- HH:mm(这是从 END 开始的)
我不知道如何才能做到这一点 - 请帮助我:)
I get my data out of my db with the following code:
private void fillData() {
cursor = mDbAdapter.fetchAllSubjects();
startManagingCursor(cursor);
String[] from = new String[] { DatabaseAdapter.KEY_TITLE, DatabaseAdapter.KEY_LECTURER, DatabaseAdapter.KEY_BEGIN };
int[] to = new int[] { R.id.title, R.id.lecturer, R.id.time };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter subjects = new SimpleCursorAdapter(this, R.layout.subject_row, cursor, from, to);
setListAdapter(subjects);
}
Now my problem is, that I want to add 3 other columns from my db and want to get the following:
- "("+DatabaseAdapter.KEY_TYPE+") "+DatabaseAdapter.KEY_TITLE
- DatabaseAdapter.KEY_LECTURER
- new Date(DatabaseAdapter.KEY_BEGIN)
- new Date(DatabaseAdapter.KEY_END)
--> these two should be in one TextView in the way dd.MM. HH:mm (this is from BEGIN) - HH:mm (this is from END)
I don't know how I'm able to do that - please help me :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我终于明白你真正想要什么了。
您可以创建自己的游标适配器,而不是直接使用“SimpleCursorAdapter”,在其中您可以根据需要对数据进行操作。
创建一个新的适配器“SubjectsAdapter.java”。在此适配器中,您将覆盖“bindView”和“newView”。这允许我们将视图应用到光标。但在此之前,我们有机会更改游标中的数据。
这会让您知道必须做什么。
Ok I finally figured out what you really wanted.
Instead of using "SimpleCursorAdapter" directly, you can create your own Cursor adapter, inside which you can mainipulate the data as you want.
Create a new Adapter "SubjectsAdapter.java". In this Adapter you will override the "bindView" and "newView". This allows us to apply a view to the cursor. But before doing so, gives us the opportunity to change the data from the cursor.
This will give you an idea what has to be done.