0

我在 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 的进度时,监听器永远不会触发。为什么?

4

2 回答 2

0

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

于 2012-06-13T10:03:50.700 回答
0

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

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

    valHospitality.setText(progress);
于 2012-06-13T01:56:28.893 回答