Search code examples
androidseekbar

SeekBar does not trigger onProgressChanged


I am using SeekBar for my Feedback Dialog in Android.

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View layout = inflater.inflate(R.layout.feedbackview, (ViewGroup) findViewById(R.id.seekHospitality));

    SeekBar hospitalitySeek = (SeekBar) layout.findViewById(
            R.id.seekHospitality);
    hospitalitySeek.setProgress(5);
    hospitalitySeek
            .setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                public void onStopTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub

                }

                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                public void onProgressChanged(SeekBar seekBar,
                        int progress, boolean fromUser) {
                    if (seekBar.getId() == R.id.seekHospitality) {
                        TextView valHospitality = (TextView) getFeedbackDialog()
                                .findViewById(R.id.valHospitality);
                        valHospitality.setText(progress);

                    }
                }
            });

But when I change the SeekBar's progress, listener never triggers. Why?


Solution

  • I found that:

        View layout = inflater.inflate(R.layout.feedbackview, (ViewGroup) findViewById(R.id.seekHospitality));
    

    Here seekHospitality is not the root. So I change it and now it works.

    Thank you