java


findViewById problems for webview in navigation drawer


I'm getting something wrong with setcontentview & findviewbyid. I'm trying to pull up a webpage when the user, using the navigation drawer, clicks on the blackboard button.
fragment.java
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
public class BlackBoardFragment extends Fragment {
public BlackBoardFragment(){}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_blackboard, container, false);
return rootView;
}
#Override
public View onCreate( Bundle savedInstanceState){
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");
return myWebView;
}
}
and the xml file:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
I have been stuck on this for the past couple of days.
Thanks in advance!!!
-David
your fragment_blackboard.xml must contain your Webview, remember you are inside a Fragment :
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
This method must return Void! not View:
#Override
public View onCreate( Bundle savedInstanceState){
Your code must looks like:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_blackboard, container, false);
WebView myWebView = (WebView) rootView.findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");
return rootView;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
and your layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>

Related Links

Active Directory Password without SSL java
ListView not returning to exact scroll position
Can I attach to Apache HttpClient cookies from Google Chrome or Firefox?
Java hasNext() and element() Implementation in While Loop
Rules due to Annotations with JSON and Spring
Reading data from file at start to use in controller in Spring Boot
How do I choose an specific file of my file Array List?
Migrating setLibraryPaths method from 0.6.8 version
Save pdf report on database using BIRT
I want solution regarding twitter4j ads api. I searched it over stackoverflow and other sites but I unabled to get solution
Why does my Jose4j JSON Web Key cause this InvalidKeyException?
Can apache Heron be run on windows
BinaryData cannot be cast to java.lang.Integer
Precompile JSP in tomcat 8 ANT script
Inflate TextViews to LinearLayout
Success in using Android to control an external monitor via HDMI

Categories

HOME
arduino-uno
image
cookies
oracle11g
azure-data-factory
homebrew
electron
alfresco
android-4.4-kitkat
ebean
onelogin
ssl-client-authentication
jplayer
spring-tool-suite
remote-access
ups
msp430
opentracing
nas
swiftlint
kryo
object-detection
intentfilter
android-widget
one-to-many
cas
tooltipster
compatibility
stormpath
google-cloud-endpoints-v2
mapbox-gl
multilingual
serverside-rendering
dynamics-crm-2013
sharefile
graphenedb
smartcontracts
promela
hls.js
svmlight
darcs
composite-key
arrow-keys
sqldf
jspdf-autotable
time-and-attendance
medium.com
pcf
nsfilemanager
etsy
qcustomplot
ready-api
hsv
sdhc
ruby-2.2
ibaction
event-bubbling
createprocessasuser
bridge.net
tablelayout
java.util.concurrent
responsive-slides
valuechangelistener
message-driven-bean
ora-00911
pygit2
ocunit
specification-pattern
browser-detection
jspinclude
qtkit
custom-backend
subgurim-maps
django-tagging
calling-convention
cxxtest
gamequery
nsviewanimation
vc90
mdac

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App