I have created a custom ArrayAdapter that displays a list of questions. I query the db, transform that data, pass the data to an array, and then pass the array to the ArrayAdapter to display my list.
dbData = getDbData();
List<Question> questions = getQuestions(1L);
dbData.closeDb();
setContentView(R.layout.activity_questions);
adapter = new QuestionsAdapter(this, getCurrentContext(), questions, 1L, dbData);
In my app, you can then click on the various question, manipulate some stuff and come back to the main list. The underlying array has not yet changed, because the changes have been persisted in the db. I again query the db, run my transformations, and then my array is up to date. I do this in my onResume()
method, but the adapter won't recognize any changes with the notifyDataSetChanged()
method. My onResume()
looks like this:
@Override
protected void onResume() {
super.onResume();
dbData = getDbData();
questions = getQuestions(1L);
adapter = new QuestionsAdapter(this, getCurrentContext(), questions, 1L, dbData);
items.setAdapter(adapter);
}
I have to query the db, make the transformations, create my array, and then create a new adapter for my changes to show up on the main list. Why can't I just do:
@Override
protected void onResume() {
super.onResume();
dbData = getDbData();
questions = getQuestions(1L);
adapter.notifyDataSetChanges();
}
What do I need to do to make this work? Thanks for the help.