그래서이 AlertDialog
이 팝업되어 사용자가 앱을 처음 열 때 어떤 것을 올바르게 말합니다.알림 대화 상자 환경 설정이 저장되지 않음
그런 다음 CheckBox
을 클릭하고 다음에 앱을 시작할 때 대화 상자 팝업을 사용 중지 할 수 있습니다.
CheckBox
을 사용하도록 설정하면 올바르게 작동하지 않습니다. 앱이 완전히 종료 된 후 다시 시작되면 알림 대화 상자가 다시 나타납니다. 아무도 내가 한 짓을 잘못 본 것입니까?
public static final String PREFS_NAME = "MyPrefsFile1";
public CheckBox dontShowAgain;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlertDialog.Builder adb = new AlertDialog.Builder(this);
LayoutInflater adbInflater = LayoutInflater.from(this);
View eulaLayout = adbInflater.inflate(R.layout.custom_dialog, null);
dontShowAgain = (CheckBox)eulaLayout.findViewById(R.id.checkBox1);
adb.setView(eulaLayout);
adb.setTitle("Alert Dialog");
adb.setMessage("My Customer Alert Dialog Message Body");
adb.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
//CheckBox Confirm for Alert Dialog
public void onClick(DialogInterface dialog, int which) {
String checkBoxResult = "NOT checked";
if (dontShowAgain.isChecked()) checkBoxResult = "checked";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("skipMessage", checkBoxResult);
// Commit the edits!
editor.commit();
return;
}
});
adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Action for 'Cancel' Button
String checkBoxResult = "NOT checked";
if (dontShowAgain.isChecked()) checkBoxResult = "checked";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("skipMessage", checkBoxResult);
// Commit the edits!
editor.commit();
return;
}
});
//Preferences For Alert Dialog
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String skipMessage = settings.getString("skipMessage", "NOT checked");
if (skipMessage !=("checked"))
adb.setIcon(R.drawable.icon);
adb.show();
}
여기 아래에있는 내 AlertDialog
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
android:textSize="5px" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do Not Show Me This Again" />
</LinearLayout>
들여 쓰기를 정리할 수 있습니까? 일하기가 어렵습니다. 또한, 작동하지 않는다고 말하면 오류가 있거나 결과가 부족한 것입니까? – thegrinner