0

I have an implementation of ArrayAdapter here that's responsible for populating a listview which displaying multiple views, among which a seekbar. Right now, I'm trying to implement a OnSeekBarChangeListener for these seekbars. I have a TextView next to the seekbar displaying the current progress. However, I am running into issues with updating this TextView whenever the user moves the seekbar. When the onProgessChanged method is called, I can't just call competenceItem.currentValue.setText(progress) because then the competenceItem object would have to be declared final. Now if I were to do this, my else clause wouldn't be working anymore as I obviously can't assign a new value to a final object.

What would be the best course of action here?

public View getView(int position, View convertView, ViewGroup parent){
    View row = convertView;
    CompetenceItem competenceItem = null;
    if (row == null) {

        ...

        competenceItem = new CompetenceItem();
        competenceItem.seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            int progressChanged = 0;

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
                progressChanged = progress;
            }

            ...

        });
        competenceItem.currentValue = (TextView) row.findViewById(R.id.textview_header_competence_current_value);
        row.setTag(competenceItem);
    } else {
        competenceItem = (CompetenceItem) row.getTag();
    }

   //competenceItem gets filled with data here

    return row;
}

static class CompetenceItem{
    TextView title;
    SeekBar seekbar;
    TextView currentValue;
}
Anubis
  • 1,162
  • 4
  • 14
  • 31

1 Answers1

0

I haven't try this but, maybe you could ger rid of the else clause asigning (CompetenceItem) row.getTag() as the default value in the declaration of CompetenceItem. Then you could call competenceItem.currentValue.setText(progress) in the if clause.

Marcos
  • 4,643
  • 7
  • 33
  • 60
  • I don't think I conveyed my problem clearly enough in my original post. My problem is that the currentValue has to be updated whenever onProgressChanged is called. – Anubis Nov 09 '14 at 16:39
  • Yes, but it seems you can't call `competenceItem.currentValue.setText(progress)` because `CompetenceItem` must be declared as final... but if you declares it as final then in the `else` clause you couldn't assign any value to `CompetenceItem`. So my answer is like this: declare `CompetenceItem` as final and call `competenceItem.currentValue.setText(progress)` in your `onProgressChanged` method (and get rid of the `else` clause, of course). – Marcos Nov 09 '14 at 16:46