Possible Solution:
Replace the static class with your own. In my case, DummyItemit becomes ProfileItemand has different attributes, but DummyContentit becomes ProfileListContent.
Then replace the static block with the static { addItem ... }static method. In the following case, I need to load items from the database:
public static void setContext(Context c) {
if (db == null) db = new MyDbAdapter(c);
if (db.isOpen() == false) {
db.open();
Cursor c = db.getProfiles();
if (c.moveToFirst()) {
do {
ProfileItem item = new ProfileItem(c.getString(0), c.getString(1),
c.getString(2));
addItem(item);
} while (c.moveToNext());
}
}
}
I call the method setContextfrom my main action at the beginning of the method onCreatebefore any other operation.
public void onCreate(Bundle savedInstanceState) {
ProfileListContent.setContext(this);
...
:
public static void insertProfile(ProfileItem profile) {
db.insertProfile(profile);
addItem(profile);
}
, , ListView, .