android - how to put a progress bar in an application using tabs -
i have main java file sets series of tabs each 1 calls seperate activity in case each activity linked webpage. trying implemente progress bar in tab activity show progress bar when link clicked on regardless of tab selected. have progress bar can use single activity cant work tabs
i have progress bar defined as
getwindow().setfeatureint( window.feature_progress, window.progress_visibility_on); setcontentview(r.layout.main ); webview = (webview) findviewbyid(r.id.webview); webview.setwebchromeclient(new webchromeclient() { public void onprogresschanged(webview view, int progress) { myactivity.setprogress(progress * 100); if(progress == 100) myactivity.settitle(r.string.app_name); } }); which goes after oncreate()
here main java file
import android.app.activity; import android.app.tabactivity; import android.content.intent; import android.content.res.resources; import android.os.bundle; import android.view.menu; import android.view.menuinflater; import android.view.view; import android.view.window; import android.webkit.webchromeclient; import android.webkit.webview; import android.widget.tabhost; import android.widget.textview; public class universityofcolorado extends tabactivity{ webview webview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); tabhost host=gettabhost(); resources res = getresources(); host.addtab(host.newtabspec("one") .setindicator("",res.getdrawable(r.drawable.ic_tab_google)) .setcontent(new intent(this, hello.class))); host.addtab(host.newtabspec("two") .setindicator("colorado main site") .setcontent(new intent(this, coloradomainsitebrowser.class))); host.addtab(host.newtabspec("three") .setindicator("culearn") .setcontent(new intent(this, culearnbrowser.class))); host.addtab(host.newtabspec("four") .setindicator("culink") .setcontent(new intent(this, culinkbrowser.class))); host.addtab(host.newtabspec("five") .setindicator("mycuinfo") .setcontent(new intent(this, mycuinfobrowser.class))); host.addtab(host.newtabspec("six") .setindicator("", res.getdrawable(r.drawable.ic_tab_map)) .setcontent(new intent(this, campusbrowser.class))); host.addtab(host.newtabspec("seven") .setindicator("",res.getdrawable(r.drawable.ic_tab_notes)) .setcontent(new intent(this, noteslist.class))); host.addtab(host.newtabspec("eight") .setindicator("", res.getdrawable(r.drawable.ic_tab_help)) .setcontent(new intent(this, campusbrowser.class))); } here 1 of activities main java file calls
import android.app.activity; import android.os.bundle; import android.view.keyevent; import android.webkit.webview; import android.webkit.webviewclient; public class campusbrowser extends activity { webview webview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); webview = (webview) findviewbyid(r.id.webview); webview.setwebviewclient(new hellowebviewclient()); webview.getsettings().setjavascriptenabled(true); webview.loadurl("http://amath.colorado.edu/department/maps/bldgs.html"); } private class hellowebviewclient extends webviewclient { @override public boolean shouldoverrideurlloading(webview view, string url) { view.loadurl(url); return true; } } public boolean onkeydown(int keycode, keyevent event) { if ((keycode == keyevent.keycode_back) && webview.cangoback()) { webview.goback(); return true; } return super.onkeydown(keycode, event); } } xml file
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <webview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </linearlayout> if me figure out appreciated
hey in webviews
in oncreate method of webview[in case may tabactivity] this
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_indeterminate_progress); setcontentview(r.layout.webview_simple); } then in webview client this
private class mywebviewclient extends webviewclient { public synchronized boolean shouldoverrideurlloading(webview view, string url){ }// , ur implementation public void onpagefinished(webview view, string url) { super.onpagefinished(view, url); setprogressbarindeterminatevisibility(false); } public void onpagestarted(webview view, string url, bitmap favicon) { setprogressbarindeterminatevisibility(true); super.onpagestarted(view, url, favicon); } } hope helps. overriding onpagefinished , onpagestarted in webview client. difficult onprogresschanged. tried found simple.
Comments
Post a Comment