I have a dialog fragment which essentially contains just a single web view. I want the dialog to popup only once the web view has completed loading the URL.
This is the onCreateView
of my DialogFragment
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_A, container, false);
webView = (WebView) view.findViewById(R.id.web_view);
webView.clearCache(true);
webView.loadUrl(url);
}
The problem I have is that the web view object is created only after the onCreateView()
method is called which will be called only after show()
is called; which in turn will cause the dialog to popup.
Is there anyway that I can preload the web view before I popup the dialog?
I wouldn't use a DialogFragment
because of the LifeCycle
of the fragment. You want to load the WebView
prior to showing it to the user. Therefore I would use a CustomLayout with visibility=GONE
and then when the WebView
(inside the layout) finishes loading, I'll fade in the layout. Use FrameLayout
and put it at the top of the hierarchy.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.