[英]How to make a “Don't show this warning message again ” dialog pop-up box
I'm trying to create an Dialog to show an introduction message in my application, with a "Don't show this again" CheckBox below it. 我试图创建一个对话框以在我的应用程序中显示一个介绍消息,并在其下面带有一个“不再显示”复选框。 I do not know how to make code. 我不知道如何编写代码。
< MainActivity.java > < MainActivity.java >
@Override
protected void onStart()
{
super.onStart();
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Warning!");
Button button = (Button) dialog.findViewById(R.id.okay);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
This is my java code 这是我的Java代码
and this is my layout.xml code 这是我的layout.xml代码
< dialog.xml > < dialog.xml >
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10.0dip" >
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="@string/brick_warning"
android:textSize="15dp" />
</RelativeLayout>
<CheckBox
android:id="@+id/dont_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dont_show"
android:textSize="13dp" />
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/okay"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/dialog_continue" />
</LinearLayout>
</LinearLayout>
have a great day :) 祝你有美好的一天 :)
Hai sorry for late answer but in your problem Hai很抱歉无法及时回答,但您遇到了问题
you can easily solve it using shared preferences 您可以使用共享的首选项轻松解决它
heres the link : 这是链接 :
and the code: 和代码:
AlertDialog.Builder adb= new
AlertDialog.Builder(this);
LayoutInflater adbInflater =
LayoutInflater.from(this);
View eulaLayout = adbInflater.inflate
(R.layout.activity_main, null);
check = (CheckBox)
eulaLayout.findViewById(R.id.skip);
adb.setView(eulaLayout);
adb.setTitle("Example:");
adb.setMessage(Html.fromHtml("Type your
text here: "));
adb.setPositiveButton("Ok", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface
dialog, int which) {
String checkBoxResult = "NOT
checked";
if (check.isChecked())
checkBoxResult = "checked";
SharedPreferences settings =
getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor
editor = settings.edit();
editor.putString("noshow",
checkBoxResult);
// Commit the edits!
// sunnovalthesis();
editor.commit();
return;
} });
adb.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface
dialog, int which) {
String checkBoxResult = "NOT
checked";
if (check.isChecked())
checkBoxResult = "checked";
SharedPreferences settings =
getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor =
settings.edit();
editor.putString("noshow",
checkBoxResult);
// Commit the edits!
// sunnovalthesis();
editor.commit();
return;
} });
SharedPreferences settings =
getSharedPreferences(PREFS_NAME, 0);
String noshow = settings.getString
("noshow", "NOT checked");
if (noshow != "checked" ) adb.show();
HAPPY CODING! 祝您编码愉快!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.