0

我正在尝试访问 AlertDialog 中的 SeekBar。我需要 setOnSeekBarChangeListener() 或访问 SeekBar.getProgress() 以获取其值。我在哪里做这个?可能吗?

该对话框使用 onOptionsItemSelected 中的 showDialog(id) 显示。

以下代码在 onCreateDialog 中用于创建包含 SeekBar 的自定义内容的 AlertDialog。

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

我不能在主要活动 onCreate 中做到这一点;SeekBar 尚未创建。我以为我可以在 Ok 按钮的 onClick 处理程序中获取 SeekBar.getProgress() 值的句柄,但不能。

任何建议都会很棒!

谢谢

帕特里克

4

1 回答 1

4

你可以SeekBar通过调用findViewById()你的calibrateView,大概。

于 2010-01-27T13:57:56.273 回答