【发布时间】:2012-06-24 07:59:42
【问题描述】:
在我的 onCreate 方法中,我调用了其他方法,即 fillData() 和 fillImages。 fillData 的作用是,它用文本填充 Listview 中的一行,fillImages 将图像放入该行中。到目前为止,一切都很好。 显然,当我只在 onCreate 方法中调用 fillData 时,只会显示文本。当我调用 fillImages 时也会发生同样的情况。
问题是当我同时调用它们时,只显示我最后调用的方法的内容。 示例:当我调用它时:
@Override
public void onCreate() {
//Here is some content left away that is not important.
fillData();
fillImages()
}
我只得到了 fillImages() 方法的内容。
我做错了什么?下面是我的 onCreate()、fillData() 和 fillImages() 方法的代码。
更新:我该如何解决这个问题???
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);
mDbHelper = new RemindersDbAdapter(this);
mImageHelper = new ImageAdapter(this);
mDbHelper.open();
mImageHelper.open();
fillData();
fillImages();
registerForContextMenu(getListView());
}
//
// Fills the ListView with the data from the SQLite Database.
//
private void fillData() {
Cursor remindersCursor = mDbHelper.fetchAllReminders();
startManagingCursor(remindersCursor);
// Creates an array with the task title.
String[] from = new String[] {RemindersDbAdapter.KEY_TITLE, RemindersDbAdapter.KEY_BODY};
// Creates an array for the text.
int[] to = new int[] {R.id.text1, R.id.text2};
// SimpleCursorAdapter which is displayed.
SimpleCursorAdapter reminders = new SimpleCursorAdapter(this, R.layout.reminder_row, remindersCursor, from, to);
setListAdapter(reminders);
}
//
// Fills the ListView with the images from the SQLite Database.
//
private void fillImages() {
Cursor imageCursor = mImageHelper.fetchAllImages();
startManagingCursor(imageCursor);
// Creates an array with the image path.
String[] fromImage = new String[] {ImageAdapter.KEY_IMAGE};
// Creates an array for the text.
int[] toImage = new int[] {R.id.icon};
// SimpleCursorAdapter which is displayed.
SimpleCursorAdapter images = new SimpleCursorAdapter(this, R.layout.reminder_row, imageCursor, fromImage, toImage);
setListAdapter(images);
}
【问题讨论】:
-
你的行是如何实现的?当您将列表适配器设置为图像时,它不再设置为提醒(并且图像显然没有提醒数据,因此没有文本)
-
图像和文本是否存储在数据库的不同表中?
-
是的,它们存储在不同的数据库中。有什么解决办法吗??
标签: android sqlite simplecursoradapter android-cursor