如何在對話框中放置複選框,如果用戶沒有選中框,則正面按鈕將不起作用,負面按鈕將關閉對話框。警報對話框?
這裏是我的代碼
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
boolean agreed = sharedPreferences.getBoolean("agreed", false);
if (!agreed) {
new AlertDialog.Builder(getActivity())
.setTitle("License agreement")
.setMessage("")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("agreed", true);
editor.commit();
}
})
.setNegativeButton("No", null)
.show();
}
的可能的複製[警報對話框與文本follwed一個複選框和2個按鈕(https://stackoverflow.com/questions/4965294/alert-dialog-with-text-follwed-with-a-checkbox-and- 2按鈕) –
用複選框和消息創建一個新的佈局,然後在'setPositiveButton'中檢查是否勾選複選框。如果選中,則提交true。 –