In my onCreate method I call to other methods, namely fillData() and fillImages. What fillData does is, it fills a row in a Listview with text, fillImages puts an image in the row. So far so good.
Obviously when I ONLY call fillData in my onCreate method only the text shows up. The same happens when I just call fillImages.
The problem is when I call both of them only the content of them method that I called last shows up.
Example: When I call this:
@Override
public void onCreate() {
//Here is some content left away that is not important.
fillData();
fillImages()
}
I only get the content of the fillImages() method.
What am I doing wrong? Below you find the code for my onCreate(), fillData() and fillImages() method.
UPDATE: HOW CAN I SOLVE THIS PROBLEM???
@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);
}
You are using the term
overrideincorrectly. Method overriding is when a subclass provides a specific implementation of a method that is provided in its superclass. This is totally unrelated to the problem you are having.The reason why your code isn’t working is because you are calling
setListAdaptertwice. The second call tosetListAdapaterun-binds the first adapter and then binds the second adapter to yourListView, thus rendering your first call totally useless. YourListActivity‘sListViewcan only have one adapter (so you are going to need to merge your implementations of the two adapters somehow).