Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialog无法复用, 只能显示一次 #233

Open
shixianjie opened this issue Feb 2, 2021 · 3 comments
Open

dialog无法复用, 只能显示一次 #233

shixianjie opened this issue Feb 2, 2021 · 3 comments

Comments

@shixianjie
Copy link

我尝试创建了一个全屏对话框用来实现搜索功能, 我希望对话框中的内容可以在下次显示的时候保留, 我的代码是:
private void showSearchDialog(){ if (mSearchDialog == null) { mSearchDialog = FullScreenDialog.show(this, R.layout.dialog_search, new FullScreenDialog.OnBindView() { public void onBind(FullScreenDialog dialog, View rootView) { } }).setTitle("搜索").setOkButton("关闭"); } else { mSearchDialog.show(); } }
但是我在第二次调用showSearchDialog()的时候对话框并没有显示, 我调查到了BaseDialogshowDialog(int style)方法, 里面有一个步骤:
if (isAlreadyShown) { return; } isAlreadyShown = true;
变量isAlreadyShown在被显示一次后被设置为true, 但是并没有在dismiss后被设置为false, 导致dialog无法复用.

希望能快点修复

@shixianjie
Copy link
Author

另外, 因为FullScreenDialog的构造方法是private的, 我甚至无法通过继承FullScreenDialog的方法解决这一问题, 我只能写一个MyFullScreenDialog继承自BaseDialog并将FullScreenDialog的全部代码复制其中, 然后在'doDismiss'方法中加入isAlreadyShown = false来解决这一问题

@shixianjie
Copy link
Author

值得庆幸的是, isAlreadyShown并不是私有变量, 这使得我还有操作的余地

@protectedMan
Copy link

就算是私有,反射也能拿到

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants