在我的 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);
}