Part of the key functionality of my application was the task sliders, a way of representing progress towards task completion with a highly graphical interface. Allowing the user to look at a progress bar rather than a simple number or text summary.
I was having difficulty reflecting the changed progress in the summary
I found the best way to implement this was by registering an observer that would be notified of changes to the items in the List.
1: final TaskAdapter taskAdapter = new TaskAdapter(this, R.id.list, taskArrayList);
2: final DataSetObserver observer = new DataSetObserver() {
3: @Override
4: public void onChanged() {
5: populateOverviewText();
6: }
7: };
8: taskAdapter.registerDataSetObserver(observer);
Here I'm defining a new DataSetObserver and calling the method to update the textview from inside the onChanged listener.
I need to fire this listener when I edit one of the progress bars.
Here's the code for notifying the observer of a change.
1: private void attachProgressUpdatedListener(SeekBar seekBar,
2: final int position) {
3: seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
4: public void onStopTrackingTouch(SeekBar seekBar) {
5: int progress = seekBar.getProgress();
6: int task_id = (Integer) seekBar.getTag();
7: TaskHandler taskHandler = new TaskHandler(DBAdapter
8: .getDBAdapterInstance(getContext()));
9: taskHandler.updateTaskProgress(task_id, progress);
10: mList.get(position).setProgress(progress);
11: //need to fire an update to the activity
12: notifyDataSetChanged();
13: }
14: public void onStartTrackingTouch(SeekBar seekBar) {
15: // empty as onStartTrackingTouch listener not being used in
16: // current implementation
17: }
18: public void onProgressChanged(SeekBar seekBar, int progress,
19: boolean fromUser) {
20: // empty as onProgressChanged listener not being used in
21: // current implementation
22: }
23: });
No comments:
Post a Comment