findViewById(int)方法未定义

1 android fragment android-fragments android-fragmentactivity

我正在扩展片段,我得到这个错误说,该方法findViewById(int)未定义类型宋.

findViewById上的进度条和webview都出现错误.

public class Song extends Fragment{


    ProgressBar progressBar;


    @Override


    public View onCreateView(LayoutInflater inflater, ViewGroup container,


    Bundle savedInstanceState) {


    View myFragmentView = inflater.inflate(R.layout.song, container, false);


    return myFragmentView;


    progressBar = (ProgressBar)findViewById(R.id.progressBar);


    final WebView mWebView = (WebView)findViewById(R.id.Browsery);


    mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);


    mWebView.loadUrl("....");


    mWebView.setWebViewClient(new WebViewClient(){



    public void onPageFinished(WebView view, String url){


    progressBar.setVisibility(View.INVISIBLE);
    }

    });
Run Code Online (Sandbox Code Playgroud)

我需要帮助

谢谢.

Rob*_*ood 5

您正在以错误的方式查找视图,view object并在findViewById中追加,如下所示:

 progressBar = (ProgressBar)myFragmentView.findViewById(R.id.progressBar);
 final WebView mWebView = (WebView)myFragmentView.findViewById(R.id.Browsery);
Run Code Online (Sandbox Code Playgroud)