SeekBar不会触发onProgressChanged

时间:2012-06-12 19:15:48

标签: android seekbar

我在Android中使用SeekBar作为我的反馈对话。

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);

                    }
                }
            });

但是当我改变SeekBar的进度时,听众永远不会触发。为什么呢?

2 个答案:

答案 0 :(得分:0)

我知道您是否尝试在OnProgressChanged中添加调试消息,但您可以尝试替换

    valHospitality.setText(String.valueOf(progress));

    valHospitality.setText(progress);

答案 1 :(得分:0)

我发现:

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

这里寻求热情不是根本。所以我改变它,现在它可以工作。

谢谢