【发布时间】:2015-08-28 14:17:33
【问题描述】:
我创建了一个用于不同活动的 AlertDialog 片段。由于某种原因,警报不会被解除,并且主要活动中的代码不会继续。我输入了很多日志命令来查看它停止的确切位置。以下是我的警报对话框:
public class Convert_units_dialog extends DialogFragment {
final static String TAG = "TAG_convert_units";
public static Convert_units_dialog newInstance() {
Convert_units_dialog frag = new Convert_units_dialog();
Bundle args = new Bundle();
args.putInt("title", R.string.change_units_dialog);
frag.setArguments(args);
return frag;
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("title");
return new AlertDialog.Builder(getActivity())
.setTitle(title)
.setPositiveButton(R.string.convert, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "inside click listener");
convert_units();
//dismiss dialog here
Log.i(TAG, "Start dismiss");
dismiss();
Log.i(TAG, "End dismiss");
}
})
.setNegativeButton(R.string.dont_convert,null)
.create();
}
在我的活动中,我创建了一个调用 alertDialog 的函数。
private void open_alert_dialog() {
DialogFragment newFragment = Convert_units_dialog.newInstance();
newFragment.show(getFragmentManager(), "dialog");
Log.i(TAG,"open_alert_dialog finished");
}
当我运行我的代码时,我在日志中看到“结束关闭”,并且从未看到“open_alert_dialog 完成”,因此我的活动中此命令之后的代码没有运行。有什么明显的我做错了吗?我已经尝试了很多我见过的建议,但到目前为止都没有奏效。
我对一般编程有点陌生,如果有任何意见,我将不胜感激。谢谢。
【问题讨论】:
-
当您单击“正”按钮时,您的应用程序是否崩溃?您应该在 logcat 崩溃时复制/粘贴它。
标签: android android-alertdialog dismiss