【发布时间】:2013-08-23 14:50:19
【问题描述】:
我对 Java 和 Android 开发非常陌生。我希望能够使用片段在我的应用程序中显示本地页面页面(因为我不希望整个应用程序都基于网络)。
所以,我进入了我的 arview.xml 并添加了一个片段:
<fragment
android:id="@+id/fragment_bbc"
android:name="android.webkit.WebViewFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
现在,我想在其中放置一个网页(目前,我将使用 bbc 网站)。
在我的“onCreate(Bundle savedInstanceState)”中,我有这个:
webFrag = (WebViewFragment) mGUIView.findViewById(R.id.fragment_bbc);
mWebView = (WebView) mGUIView.findViewById(R.id.fragment_bbc);
myWebView.loadUrl("http://www.bbc.co.uk");
我有所有这 3 行的错误,都说它们无法解决。
我哪里错了?谢谢
【问题讨论】:
-
一般在fragment中在onCreateView方法中使用findviewbyid(),然后在onviewCreated()中做一些处理。
-
这是什么MGUIView?如果它是您的 mainActivity,则您不需要当前视图的引用。
-
MGUIView = (RelativeLayout) getLayoutInflater().inflate(R.layout.arview, null);