创建一个TDialog給常量,每次常量的显示viewholder的内存地址都会变换
zwping opened this issue · comments
做一个界面弹窗条件输入,条件通过EditText输入,弹窗通过TDialog承载;
每次条件输入完成,会隐藏弹窗。之后需要重新输入条件就再打开弹窗。
这时问题出现了,每次show()之后Fragment都会重新创建,应当怎么避免DialogFragment重新创建呢?
create()方法会创建新的TDialog对象,show()方法不会的.能再详细描述下你的需求吗?
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (null == rootView) {
if (getLayoutRes() > 0) {
rootView = inflater.inflate(getLayoutRes(), container, false);
}
if (getDialogView() != null) {
rootView = getDialogView();
}
}
// 缓存的rootView需要判断是否已经被加过parent,如果有parent需要从parent删除,要不然会发生这个rootView已经有parent的错误。
ViewGroup parent = (ViewGroup) rootView.getParent();
if (null != parent) parent.removeView(rootView);
bindView(rootView);
return rootView;
}
private View rootView;