私の 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);
}