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 on the SeekBar.getProgress() value in the Ok Button's onClick handler but could not.
Any suggestions would be great!
thanks
patrick