android - Defining cards as WebViews while still using CardScrollView: Google Glass -
i'm trying develop simple glass example (immersion) each card displays webview in fullscreen (not within cardbuilder.layout.embed_inside).
i'm following answer: google glass immersion custom layout without cardbuilder.layout.embed_inside it's not clear where setup webviews.
my code follows:
public class mainactivity extends activity { private string cardpageone = "file:///android_asset/one.html"; private string cardpagetwo = "file:///android_asset/two.html"; private cardscrollview mcardscrollview; private examplecardscrolladapter madapter; private list<view> mcards; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); createcards(); // setup webviews mcardscrollview = new cardscrollview(this); madapter = new examplecardscrolladapter(); mcardscrollview.setadapter(madapter); mcardscrollview.activate(); setcontentview(mcardscrollview); } private void createcards() { mcards = new arraylist<>(); webview myweb = (webview)findviewbyid(r.id.webview); myweb.getsettings().setjavascriptenabled(false); myweb.loadurl(filepath); mcards.add(myweb); webview myweb2 = (webview)findviewbyid(r.id.webview); myweb2.getsettings().setjavascriptenabled(false); myweb2.loadurl(filepathalt); mcards.add(myweb2); } private class examplecardscrolladapter extends cardscrolladapter { @override public int getposition(object item) { return mcards.indexof(item); } @override public int getcount() { return mcards.size(); } @override public object getitem(int position) { return mcards.get(position); } @override public int getviewtypecount() { // correct? each card have different (web)view return mcards.size(); } @override public int getitemviewtype(int position) { // correct? return position; } @override public view getview(int position, view convertview, viewgroup parent) { return mcards.get(position); } } }
lastly, webview.xml follows:
<?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"></webview>
i'm getting java.lang.nullpointerexception code reaches:
myweb.getsettings().setjavascriptenabled(false);
i believe happens because myweb has not been set content view, i'm using mcardscrollview. if so, , how can setup webviews?
the error in detail is:
07-13 17:24:05.337 18117-18117/? e/androidruntime﹕ fatal exception: main process: com.testwebviewscroller, pid: 18117 java.lang.runtimeexception: unable start activity componentinfo{com.testwebviewscroller/com.testwebviewscroller.mainactivity}: java.lang.nullpointerexception @ android.app.activitythread.performlaunchactivity(activitythread.java:2224) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2273) @ android.app.activitythread.access$800(activitythread.java:138) @ android.app.activitythread$h.handlemessage(activitythread.java:1236) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:149) @ android.app.activitythread.main(activitythread.java:5045) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:602) @ dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ com.testwebviewscroller.mainactivity$examplecardscrolladapter.getview(mainactivity.java:101) @ com.google.android.glass.widget.cardscrollview.loadview(cardscrollview.java:1351) @ com.google.android.glass.widget.cardscrollview.addchildview(cardscrollview.java:1239) @ com.google.android.glass.widget.cardscrollview.updateviewsinternal(cardscrollview.java:1131) @ com.google.android.glass.widget.cardscrollview.updateviews(cardscrollview.java:1193) @ com.google.android.glass.widget.cardscrollview.activate(cardscrollview.java:1589) @ com.testwebviewscroller.mainactivity.oncreate(mainactivity.java:40) @ android.app.activity.performcreate(activity.java:5235) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1089) @ android.app.activitythread.performlaunchactivity(activitythread.java:2188) at android.app.activitythread.handlelaunchactivity(activitythread.java:2273) at android.app.activitythread.access$800(activitythread.java:138) at android.app.activitythread$h.handlemessage(activitythread.java:1236) at android.os.handler.dispatchmessage(handler.java:102) at android.os.looper.loop(looper.java:149) at android.app.activitythread.main(activitythread.java:5045) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:515) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) at com.android.internal.os.zygoteinit.main(zygoteinit.java:602) at dalvik.system.nativestart.main(native method)
if want put webview card, why don't inflate own view each item inside of getview()
override method? if aren't going use layout provided cards might create new layout , use that. getview()
this:
@override public view getview(int position, view convertview, viewgroup parent) { layoutinflater layoutinflater = (layoutinflater) mcontext.getsystemservice(context.layout_inflater_service); convertview = layoutinflater.inflate(r.layout.webview, parent, false); //enter code here handle custom view loading return convertview; }
Comments
Post a Comment