I’m struggling to find the best way to implement my update to the database
The code below is in the adapter for a list view, so each list item has its own seekbar.
The list is of homework assignments so each item has its own degree of completion which I need to persist to a database.
I have a business method which can do the database write, it just needs the id of the assignment and the new progress value.
private void attachProgressUpdatedListener(SeekBar seekBar) {
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
// need to update database with new progress here!
}
public void onStartTrackingTouch(SeekBar seekBar) {
// empty as onStartTrackingTouch listener not being used in
// current implementation
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// empty as onProgressChanged listener not being used in current
// implementation
}
});
}
the problem I’m having is getting a handle to my AssignmentHandler which deals with the database reads / writes. I can pass the assignment_id to my attachProgressUpdatedListener without any issues but I’m not sure this is the best way to go about it as I haven’t got / not sure I want an instance of AssignmentHandler instantiated inside the ArrayAdapter.
You can store the element’s database ID in each SeekBar’s “tag” (setTag() and getTag() methods), and use that to update the database from the onStopTracking method.