次のコードのチェックボックスがある PreferenceScreen があります。
<CheckBoxPreference
android:defaultValue="false"
android:key="the_key"
android:summary="Random text here."
android:title="My Title"
/>
設定ボタンとキャンセルがあるこのチェックボックスをクリックすると、ポップアップメッセージが表示されるようにします。「設定」が押されると、以前にチェックされていなかった場合はチェックボックスがチェックされ、その逆になります。どうやってやるの?これが私のポップアップメッセージのコードです。
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Some message that will be displayed")
.setPositiveButton(R.string.set, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do something
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
また、チェックボックスの値(チェックされているかどうか)を取得するにはどうすればよいですか? ありがとう!!