Java – using action tabs and WebView
•
Java
I want to have my application to display tabs at the top of the screen (make it work) and set up WebView. XML in the XML file I couldn't get WebView and snippet code because I got the "inaccessible declaration"
import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.app.Activity; import android.webkit.WebView; public class TopRatedFragment extends Activity { public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_top_rated,container,false); return rootView; //Unreachable Statement WebView engine = (WebView) findViewById(R.id.web_engine); engine.loadUrl("http://www.google.com/"); } }
Does anyone have any suggestions?
Solution
Use the following code:
import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.app.Activity; import android.webkit.WebView; public class TopRatedFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater,Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_top_rated,false); WebView engine = (WebView) rootView.findViewById(R.id.web_engine); // `web_engine` must be in `fragment_top_rated` engine.loadUrl("http://www.google.com/"); return rootView; } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码