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

Alternative to Font.createFont()?
Java BufferedReader.readLine() returning null when reading file
Class<T> and class keyword in Java
Changing an array input to a display a letter such as “X” or “O”
About java Timer
In spring mvc, how to link to another jsp using #RequestMapping?
Java Triangle class, getArea method constantly returning 0.0? [duplicate]
While loop printing incorrectly
Java Concurrency Issues concerning Listeners
Android - SharedPreferences Error related to Context
Application development (behind the scenes) [closed]
java.lang.ArrayIndexOutOfBoundsException?
Android finish Thread
incompatible types: java.lang.String cannot be converted to String
Selenium - NoSuchElementException error checking
what's the use of EjbContext and how it can be useful in Ejb applications?

Categories

HOME
compiler-construction
wso2-am
fluentd
ngrx
jira
yarn
google-project-tango
azure-storage-tables
uber-api
bs4
webrequest
adfs
virtualization
gnupg
spring-xd
qt-creator
postgres-xl
resize
gz
zebra-printers
jsprit
autoconf
clickonce
p-value
one-to-many
centos6.5
dynamic-featured-image
facebook-access-token
kannel
brunch
windows-error-reporting
publish
quote
file-rename
gsoap
xmlreader
streamsets
ssjs
dism
powershell-dsc
firebase-admin
babel-core
xml-documentation
osx-mavericks
apache-fop
atomicity
font-size
sybase-asa
mako
flutterwave
vtigercrm
android-fonts
instant
bonobo
thrust
nsfilemanager
multiple-regression
react-native-listview
master-slave
hexdump
asp.net5
rtbkit
lib.web.mvc
ora-00900
tmuxinator
security-testing
embedded-code
umbraco6
camanjs
cdt
relocation
navigationservice
doskey
seaside
jboss-weld
resty-gwt
app42
algebraic-data-types
farseer
runtime.exec
pushbackinputstream
android-screen-support
mt
manchester-syntax
multipage
postgresql-performance
subscript
django-tagging
xdomainrequest
visitor-statistic
asp.net-mvc-areas
wise
mirah
webkit.net
libs
javap
temporal-database
gacutil
data-acquisition

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