gpt4 book ai didi

java - 如何让一个 "Don' t再次显示这个警告信息”对话框弹出

转载 作者:行者123 更新时间:2023-11-30 11:38:38 26 4
gpt4 key购买 nike

我正在尝试创建一个对话框以在我的应用程序中显示一条介绍消息,其下方有一个“不再显示”复选框。不会写代码。

<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();
}

这是我的java代码

这是我的 layout.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>

祝你有美好的一天:)

最佳答案

Hai 很抱歉回答晚了但是在你的问题中
您可以使用共享首选项轻松解决它
这是 link :

和代码:

          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();

编码愉快!

关于java - 如何让一个 "Don' t再次显示这个警告信息”对话框弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13558209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com