java - how to add simple code to an android application -
i have confusion regarding put regular java code in android application.
i'm using eclipse sdk , default when create application makes .java file oncreate() method. put code, inside method?
right in layout have imagebutton, once button clicked want open new webview page gets it's html code index.html file found in assets folder. have far...
button button = (button)findviewbyid(r.id.imagebutton1); if(button.ispressed()) { webview webview = new webview(null); setcontentview(webview); try { inputstream fin = getassets().open("index.html"); byte[] buffer = new byte[fin.available()]; fin.read(buffer); fin.close(); webview.loaddata(new string(buffer), "text/html", "utf-8"); } catch (ioexception e) { e.printstacktrace(); } }
i have block of code @ end of oncreate() method right under line:
setcontentview(r.layout.main);
however, once run program crashes , tells me failed start. i'm assuming has fact code in oncreate. know not i'm supposed put it, can't think of anywhere else code should go. supposed make new .java file , have main method there? i'm taking classes c++ , c# android thing still new me.
have done tutorials? if not start there learn basics of creating , working android activity
. once have worked way through them, read application fundamentals understand lifecycle more fully.
Comments
Post a Comment