Argardor
Argardor

Reputation: 79

Cannot resolve method 'getLayoutInflater()' - Android Java

I want add a fullscreen mode in my webView -for youtube videos-. I have found that exemple https://stackoverflow.com/a/16179544/5070495. I have follow all the step, adapt the code, but i have a problem.

I use rootView for my layout but i didn't know how use it before a getLayoutInflater().

The problem is :

View loadingView = getLayoutInflater().inflate(R.layout.view_loading_video, null); // Your own view, read class comments

All the code :

public class vod extends Fragment {
    private WebView wv7;
    public static final String TAG = "VOD";
    private VideoEnabledWebView webView;
    private VideoEnabledWebChromeClient webChromeClient;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


        View rootView = inflater.inflate(R.layout.vod, container, false);
        // Set layout
        //rootView.findViewById(R.layout.vld);

        // Save the web view
        wv7 = (VideoEnabledWebView) rootView.findViewById(R.id.webView7);

        // Initialize the VideoEnabledWebChromeClient and set event handlers
        View nonVideoLayout = rootView.findViewById(R.id.nonVideoLayout); // Your own view, read class comments
        ViewGroup videoLayout = (ViewGroup) rootView.findViewById(R.id.videoLayout); // Your own view, read class comments
        View loadingView = getLayoutInflater().inflate(R.layout.view_loading_video, null); // Your own view, read class comments
        webChromeClient = new VideoEnabledWebChromeClient(nonVideoLayout, videoLayout, loadingView, webView) // See all available constructors...
        {
            // Subscribe to standard events, such as onProgressChanged()...
            @Override
            public void onProgressChanged(WebView view, int progress) {
                // Your code...
            }
        };
        webChromeClient.setOnToggledFullscreen(new VideoEnabledWebChromeClient.ToggledFullscreenCallback() {
            @Override
            public void toggledFullscreen(boolean fullscreen) {
                // Your code to handle the full-screen change, for example showing and hiding the title bar. Example:
                if (fullscreen) {
                    WindowManager.LayoutParams attrs = getActivity().getWindow().getAttributes();
                    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
                    attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
                    getActivity().getWindow().setAttributes(attrs);
                    if (android.os.Build.VERSION.SDK_INT >= 14) {
                        getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
                    }
                } else {
                    WindowManager.LayoutParams attrs = getActivity().getWindow().getAttributes();
                    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
                    attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
                    getActivity().getWindow().setAttributes(attrs);
                    if (android.os.Build.VERSION.SDK_INT >= 14) {
                        getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
                    }
                }

            }
        });
        wv7.setWebChromeClient(webChromeClient);

        // Navigate everywhere you want, this classes have only been tested on YouTube's mobile site
        wv7.loadUrl("http://m.youtube.com");


    }
    public void onBackPressed()
    {
        // Notify the VideoEnabledWebChromeClient, and handle it ourselves if it doesn't handle it
        if (!webChromeClient.onBackPressed())
        {
            if (wv7.canGoBack()) {
                wv7.goBack();
            }
        }
    }
}

Thank you for your help :p

Upvotes: 0

Views: 2147

Answers (1)

krystian71115
krystian71115

Reputation: 1937

Why are you calling getLayoutInflater? You have inflater from parameters Change it:

View loadingView = inflater.inflate(R.layout.view_loading_video, null); // Your own view, read class comments

Edit: The second solution:

View loadingView = getActivity().getLayoutInflater().inflate(R.layout.view_loading_video, null);

But i think the first solution is better.

Upvotes: 1

Related Questions