我想从活动时重新启动被解雇建有警报建设者prevent对话框。
I am trying to prevent dialogs built with Alert builder from being dismissed when the Activity is restarted.
如果我重载onConfigurationChanged方法我能成功地做到这一点,重新布局,以正确的方向,但我失去的EditText粘文本特征。因此,在解决对话框的问题,我创造了这个的EditText问题。
If I overload the onConfigurationChanged method I can successfully do this and reset the layout to correct orientation but I lose sticky text feature of edittext. So in solving the dialog problem I have created this edittext problem.
如果我救了弦从EditText上,并重新分配他们在onCofiguration变化,他们似乎仍然默认为初始值旋转前没有输入的内容。即使我强制无效似乎并更新它们。
If I save the strings from the edittext and reassign them in the onCofiguration change they still seem to default to initial value not what was entered before rotation. Even if I force an invalidate does seem to update them.
我真的需要解决或者对话框的问题或问题的EditText
I really need to solve either the dialog problem or the edittext problem.
感谢您的帮助。
要避免这个问题现在最好的办法是使用DialogFragment.
The best way to avoid this problem nowadays is by using a DialogFragment
.
创建延伸DialogFragment.覆盖onCreateDialog并返回旧 对话框
或AlertDialog.
然后你可以用DialogFragment.show(fragmentManager,标签) 。
Then you can show it with DialogFragment.show(fragmentManager, tag)
.
下面是一个Listener:
public class MyDialogFragment extends DialogFragment {
public interface YesNoListener {
void onYes();
void onNo();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (!(activity instanceof YesNoListener)) {
throw new ClassCastException(activity.toString() + " must implement YesNoListener");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.dialog_my_title)
.setMessage(R.string.dialog_my_message)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((YesNoListener) getActivity()).onYes();
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((YesNoListener) getActivity()).onNo();
}
})
.create();
}
}
而在您调用活动:
And in the Activity you call:
new MyDialogFragment().show(getSupportFragmentManager(), "tag"); // or getFragmentManager() in API 11+
这答案混合这三个问题(和他们的答案):
This answer mixes these three questions (and their answers):
避免对话框 Android的最佳途径设备旋转后关闭 的Android DialogFragment VS对话 我如何能表现出DialogFragment使用兼容包? Android Best way of avoid Dialogs to dismiss after a device rotation Android DialogFragment vs Dialog How can I show a DialogFragment using compatibility package?