簡體   English   中英

對於類型FacebookFragment,未定義方法findViewById(int)

[英]The method findViewById(int) is undefined for the type FacebookFragment

我有一個片段活動: 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)尚未定義 我不知道該怎么辦,請有人幫忙! 我正在使用日食。

正確

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM