Error: cannot find symbol method findViewById(int)

前端 未结 1 1650
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 06:40

I\'m experiencing an issue with WebViews within my small app. I have the relevant webview with the correct information in my layouts and I have sample code directly from the And

相关标签:
1条回答
  • 2021-01-25 07:40
     WebView myWebView = (WebView) rootView.findViewById(R.id.webview);
    

    Change your onCreateView method to:

    private WebView webView;
    
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.fragment_transition_scene_1, container, false);
        final Scene scene = Scene.getSceneForLayout(container, R.layout.fragment_transition_scene_2, getActivity());
        Button goButton = (Button)rootView.findViewById(R.id.goButton);
        goButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TransitionManager.go(scene);
                webView myWebView = (WebView) rootView.findViewById(R.id.webview);
    
                webView.getSettings().setJavaScriptEnabled(true);
                webView.getSettings().setLoadWithOverviewMode(true);
                webView.getSettings().setUseWideViewPort(true);
                webView.setWebViewClient(new WebViewClient(){
    
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        progDailog.show();
                        view.loadUrl(url);
    
                        return true;
                    }
                    @Override
                    public void onPageFinished(WebView view, final String url) {
                        progDailog.dismiss();
                    }
                });
    
                webView.loadUrl("http://www.example.com");
    
                Log.d("","Loading Finished");
            }
        });
        return rootView;
    }
    
    0 讨论(0)
提交回复
热议问题