interface - Android -- Visible and Invisible Tabs: Button Handling -


i trying create application login screen appears , has effects among various other tabs.

i have tabbed implementation working fine: can hide tabs , view layouts of other tabs -- however, cannot make them reappear. program runs fine when not attempt button handling, whenever start listener, force-close.

attached problem code: can't find i'm getting force close from, know in button listener area.

essentially, want tabs appear if user's name , password correct.

what seeing 1 of 4 tabs. specifically, looking @ login screen tab.

code:

public class loginactivity extends activity {  tabhost tabhost = (tabhost) findviewbyid(android.r.id.tabhost);  public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      setcontentview(r.layout.login);      final button btn = (button) findviewbyid(r.id.login_button);      btn.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {              edittext txt_username = (edittext) findviewbyid(r.id.txt_username);             edittext txt_password = (edittext) findviewbyid(r.id.txt_username);              if (txt_username.tostring().equals("bob")                     && txt_password.tostring().equals("123")) {                 tabhost.gettabwidget().getchildat(0)                         .setvisibility(view.visible);                 tabhost.gettabwidget().getchildat(1)                         .setvisibility(view.visible);                 tabhost.gettabwidget().getchildat(2)                         .setvisibility(view.visible);                 tabhost.gettabwidget().getchildat(3)                         .setvisibility(view.gone);             }         }     }); } } 

attached logcat (very long)

04-12 17:07:31.465: error/androidruntime(1480): fatal exception: main 04-12 17:07:31.465: error/androidruntime(1480): java.lang.runtimeexception: unable start activity componentinfo{android.waiter/android.waiter.waiter}: java.lang.runtimeexception: unable start activity componentinfo{android.waiter/android.waiter.loginactivitygroup}: java.lang.runtimeexception: unable instantiate activity componentinfo{android.waiter/android.waiter.loginactivity}: java.lang.nullpointerexception  04-12 17:07:31.465: error/androidruntime(1480):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2663)  04-12 17:07:31.465: error/androidruntime(1480):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2679)  04-12 17:07:31.465: error/androidruntime(1480):     @ android.app.activitythread.access$2300(activitythread.java:125)  04-12 17:07:31.465: error/androidruntime(1480):     @ android.app.activitythread$h.handlemessage(activitythread.java:2033)  04-12 17:07:31.465: error/androidruntime(1480):     @ android.os.handler.dispatchmessage(handler.java:99)  04-12 17:07:31.465: error/androidruntime(1480):     @ android.os.looper.loop(looper.java:123)  04-12 17:07:31.465: error/androidruntime(1480):     @ android.app.activitythread.main(activitythread.java:4627)  04-12 17:07:31.465: error/androidruntime(1480):     @ java.lang.reflect.method.invokenative(native method)  04-12 17:07:31.465: error/androidruntime(1480):     @ java.lang.reflect.method.invoke(method.java:521)  04-12 17:07:31.465: error/androidruntime(1480):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868)  04-12 17:07:31.465: error/androidruntime(1480):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626)  04-12 17:07:31.465: error/androidruntime(1480):     @ dalvik.system.nativestart.main(native method) 

i suggest have 2 seperate activities login , other activity tabs. code have simple change:

btn.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {              edittext txt_username = (edittext) findviewbyid(r.id.txt_username);             edittext txt_password = (edittext) findviewbyid(r.id.txt_username);              if (txt_username.tostring().equals("bob")                     && txt_password.tostring().equals("123")) {                 startactivity(new intent(this,yourtabactivity.class));             }         }     }); 

i use tablayout tab-style view quite easy implement. feel free use view prefer , know better


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -