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()値のハンドルを取得できると思いましたが、できませんでした。
どんな提案も素晴らしいでしょう!
ありがとう
パトリック