开发者

How to set OnSeekBarChangedListener for SeekBar used in AlertDialog via LayoutInflater

I am trying to access a SeekBar in a AlertDialog. I need to either setOnSeekBarChangeListener(), or access the SeekBar.getProgress() to get its value. Where do I do this? Is it possible?

The dialog is shown using showDialog(id) from onOptionsItemSelected.

The following code is used in onCreateDialog to create the AlertDialog with custom content which includes a SeekBar.

case CALIBRATE_DIALOG_ID: {
            // This example shows how to add a custom layout to an AlertDialog
            LayoutInflater factory = LayoutInflater.from(this);
            final View calibrateView = factory.inflate(R.layout.dlg_calibrate, null);
            return new AlertDialog.Builder(this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle("Calibrate")
                .setView(calibrateView)
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        //mSeekBar1 = (SeekBar) findViewById(R.id.SeekBar01);
                        //Toast.makeText(ctx, mSeekBar1.getProgress(), Toast.LENGTH_SHORT);

                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                })
                .create();
        }

I can't do it in the main activity onCreate; the SeekBar has not been created yet. I thought I would be able to get a handle o开发者_StackOverflow社区n the SeekBar.getProgress() value in the Ok Button's onClick handler but could not.

Any suggestions would be great!

thanks

patrick


You can get your SeekBar by calling findViewById() on your calibrateView, presumably.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜