At the start of my App i show a Dialog. In this dialog I have 2 spinners. If I change the entry of the first spinner the app loads a JSON file and parses it into a database. Then the spinner gets filled with a SimpleCursorAdapter from the database where the JSON file was saved. The problem is that when I change the first spinner it always loads the database which was saved the last time the spinner was changed.
Here's my code from the onItemSelected method:
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
dialogs.dismiss();
}
};
Thread checkUpdate = new Thread() {
public void run() {
klassenListeAktualisieren((new Long(txtBerufID)).toString());
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
dbHelperKlasse = new KlassenlisteDbAdapter(myContext);
dbHelperKlasse.open();
Cursor cursor_Names = dbHelperKlasse.fetchAllOfThem();
startManagingCursor(cursor_Names);
String[] columns = new String[] { dbHelperKlasse.KEY_TITLE };
int[] to = new int[] { android.R.id.text1 };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(myContext, android.R.layout.simple_spinner_item,cursor_Names, columns, to);
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
klassenSpinner.setAdapter(mAdapter);
Let me know if you need to know anything else (Code etc.).
For everybody who faces the same problem here's the solution:
Create a new method where you put in your fetch call to the database and where you populate your spinner.
Afterwards, in the handleMessage()
method of your Handler
(where I closed my Dialog
), call this method. So the spinner gets filled after he wrote into the database and not during this process (and then showing the "old" data from the database).