从Dialog获取搜索栏进度

时间:2014-04-16 14:59:34

标签: java android

我正在尝试构建一个使用自定义布局的对话框,但是我无法从搜索栏获取音量和增益值,它会给出一个nullpointer异常。 这是代码:

        Dialog soundoptions= new Dialog(this);
    soundoptions.setContentView(R.layout.soundoptions);

    soundoptions.setTitle("Sound Options");
    soundoptions.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            SeekBar vs=(SeekBar) findViewById(R.id.volume);
            SeekBar vg=(SeekBar) findViewById(R.id.gain);
            vg.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

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

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                        boolean fromUser) {
                    // TODO Auto-generated method stub
                    gain=progress;

                }
            });
           vs.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

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

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                volume=progress;

            }
        });

1 个答案:

答案 0 :(得分:1)

vs和vg为空。

使用......

SeekBar vs=(SeekBar) dialog.findViewById(R.id.volume);
SeekBar vg=(SeekBar) dialog.findViewById(R.id.gain);

注意“对话框”......