gpt4 book ai didi

android - 方法 findViewById(int) 未定义

转载 作者:行者123 更新时间:2023-11-29 15:23:58 25 4
gpt4 key购买 nike

我正在扩展 fragment ,但我收到此错误消息,findViewById(int) 方法未针对 Song 类型定义。

我的进度条和 webview 在 findViewById 上都出现错误。

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);
}

});

我需要帮助

谢谢。

最佳答案

您以错误的方式查找 View ,在 findViewById 时附加 view object,如下所示:

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

关于android - 方法 findViewById(int) 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14974409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com