我有一个显示视图的对话框片段。当我显示视图时,它工作正常。尽管当我从横向/纵向更改其方向时,反之亦然,对话框片段消失了。我尝试了一些建议,尽管没有奏效。
这是Dialog片段的精简版本,我添加了onSaveInstanceState以保存状态,并尝试在onCreateView中对其进行调用。虽然不起作用。 任何帮助解决此问题的建议将不胜感激。 吉姆
public class BalanceOverlay extends DialogFragment implements View.OnClickListener {
public BalanceOverlay() {
// Empty constructor is required for DialogFragment
// Make sure not to add arguments to the constructor
// Use `newInstance` instead as shown below
}
public static BalanceOverlay newInstance(String title) {
BalanceOverlay frag = new BalanceOverlay();
Bundle args = new Bundle();
args.putString("Balance - The Center of the Plate", title);
frag.setArguments(args);
return frag;
}
@Override
public void onDestroyView() {
if (getDialog() != null && getRetainInstance()) {
getDialog().setDismissMessage(null);
}
super.onDestroyView();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
bview= inflater.inflate(R.layout.balance, container);
//setRetainInstance(true);
return bview;
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putLong("param", value);
}
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (savedInstanceState != null){
value = savedInstanceState.getLong("param");
}