gpt4 book ai didi

java - Android 中的自定义警报框

转载 作者:行者123 更新时间:2023-12-02 00:03:26 24 4
gpt4 key购买 nike

下面的类位于文件 Test.java 中,我想从公共(public)类 Test 的函数中调用它。现在我不知道如何访问该函数来显示alertdialog。我的意思是如何从另一种方法访问下面的类的 onCreateDialog(Bundle savingInstanceState)

以下代码复制自 this source

  class MyCustomDialog extends DialogFragment{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();

// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.notification_list_layout, null))
// Add action buttons
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// sign in the user ...
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyCustomDialog.this.getDialog().cancel();
}
});
return builder.create();
}

}

我想要这样的东西 enter image description here

最佳答案

MyCustomDialog custDialog = new MyCustomDialog();
custDialog.show(custDialog.getFragmentManager(), "Info");

关于java - Android 中的自定义警报框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14373329/

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