对于FacebookFragment类型,方法findViewById(int)未定义

时间:2016-03-18 15:30:02

标签: android eclipse android-fragments android-webview

我有片段活动: FacebookFragment.javafragmnet_facebook.xml

fragment_facebook.xml中,我添加了

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fa6a6a"
android:orientation="vertical" >
<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />
</RelativeLayout>

并在FacebookFragment.java

package com.appmaids.socialhub;
import com.appmaids.socialhub.R;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
public class FacebookFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_facebook, container, false);
    final WebView myWebview = (WebView)findViewById(R.id.webView1);
    myWebview.loadUrl("https://www.facebook.com");
    myWebview.getSettings().setJavaScriptEnabled(true);
    return rootView;
 }
}

我收到的错误是: 对于FacebookFragment类型,方法findViewById(int)未定义。 我不知道该怎么办,有人请帮忙!我正在使用eclipse。

1 个答案:

答案 0 :(得分:1)

正确

 View rootView = inflater.inflate(R.layout.fragment_facebook, container, false);
 final WebView myWebview = (WebView)rootView.findViewById(R.id.webView1);
相关问题