Android login screen that switches to tab layout? -
Android login screen that switches to tab layout? -
hi have app written after logging in correctly takes page. here code main page, when had directing plain page image worked fine:
package com.example.loginscreen; import android.app.activity; import android.content.intent; import android.graphics.color; import android.os.bundle; import android.view.menu; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; import android.widget.toast; public class mainactivity extends activity { private edittext username=null; private edittext password=null; private textview attempts; private button login; int counter = 3; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); username = (edittext)findviewbyid(r.id.edittext1); password = (edittext)findviewbyid(r.id.edittext2); attempts = (textview)findviewbyid(r.id.textview5); attempts.settext(integer.tostring(counter)); login = (button)findviewbyid(r.id.button1); } public void login(view view){ if(username.gettext().tostring().equals("mark") && password.gettext().tostring().equals("mark")){ toast.maketext(getapplicationcontext(), "login successful!", toast.length_long).show(); startactivity(new intent(mainactivity.this,loading.class)); } else{ toast.maketext(getapplicationcontext(), "wrong credentials", toast.length_short).show(); attempts.setbackgroundcolor(color.red); counter--; attempts.settext(integer.tostring(counter)); if(counter==0){ login.setenabled(false); } } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); homecoming true; } }
which switches tab layout next activities:
import android.app.activity; import android.os.bundle; import android.widget.textview; public class homepage extends activity { public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); textview textview = new textview(this); textview.settext("overview"); setcontentview(textview); } } bundle com.example.loginscreen; import android.app.activity; import android.os.bundle; import android.widget.textview; public class homepage2 extends activity { public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); textview textview = new textview(this); textview.settext("card summary"); setcontentview(textview); } } bundle com.example.loginscreen; import android.app.activity; import android.os.bundle; import android.widget.textview; public class homepage3 extends activity { public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); textview textview = new textview(this); textview.settext("details"); setcontentview(textview); } }
which link through this:
package com.example.loginscreen; import android.app.tabactivity; import android.content.intent; import android.content.res.resources; import android.os.bundle; import android.widget.tabhost; import android.widget.tabhost.tabspec; @suppresswarnings("deprecation") public class linktabs extends tabactivity { public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.link_main); resources ressources = getresources(); tabhost tabhost = gettabhost(); // first tab intent intentandroid = new intent().setclass(this, homepage.class); tabspec tabspechomepage = tabhost .newtabspec("homepage") .setindicator("", ressources.getdrawable(r.drawable.overview)) .setcontent(intentandroid); // sec tab intent intentapple = new intent().setclass(this, homepage2.class); tabspec tabspechomepage2 = tabhost .newtabspec("homepage2") .setindicator("", ressources.getdrawable(r.drawable.overview)) .setcontent(intentapple); // 3rd tab intent intentwindows = new intent().setclass(this, homepage3.class); tabspec tabspechomepage3 = tabhost .newtabspec("homepage3") .setindicator("", ressources.getdrawable(r.drawable.overview)) .setcontent(intentwindows); // add together tabs tabhost.addtab(tabspechomepage); tabhost.addtab(tabspechomepage2); tabhost.addtab(tabspechomepage3); //set windows tab default (zero based) tabhost.setcurrenttab(2); } }
but whenever run app brings first activity fine if log in correctly app stops. there no errors, , here manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.loginscreen" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="10" android:targetsdkversion="17" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.loginscreen.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".homepage" /> <activity android:name=".homepage2" /> <activity android:name=".homepage3" /> </application> </manifest>
here xml main page:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".mainactivity" > <edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbottom="@+id/textview2" android:layout_marginleft="32dp" android:layout_torightof="@+id/textview2" android:ems="10" tools:ignore="textfields" > <requestfocus /> </edittext> <edittext android:id="@+id/edittext2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbottom="@+id/textview3" android:layout_alignleft="@+id/edittext1" android:ems="10" android:inputtype="textpassword" /> <textview android:id="@+id/textview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview2" android:layout_margintop="40dp" android:layout_toleftof="@+id/edittext1" android:hint="password" android:text="@string/password" android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/textview5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/textview4" android:layout_alignbottom="@+id/textview4" android:layout_alignleft="@+id/button1" android:text="textview" tools:ignore="hardcodedtext" /> <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/textview4" android:layout_alignparenttop="true" android:layout_margintop="155dp" android:hint="username" android:text="@string/username" android:textappearance="?android:attr/textappearancemedium" /> <imageview android:id="@+id/imageview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textview3" android:layout_alignleft="@+id/textview2" android:layout_alignparenttop="true" android:src="@drawable/tranzlogo1" /> <textview android:id="@+id/textview4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview3" android:layout_margintop="26dp" android:layout_toleftof="@+id/textview5" android:text="@string/attempts" android:textappearance="?android:attr/textappearancemedium" /> <progressbar android:id="@+id/progressbar1" style="?android:attr/progressbarstylehorizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/textview4" android:layout_alignright="@+id/edittext2" android:layout_below="@+id/textview4" /> <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:layout_marginbottom="36dp" android:onclick="login" android:text="@string/login" /> </relativelayout>
and link page tab layout:
<?xml version="1.0" encoding="utf-8"?> <tabhost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"> <tabwidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <framelayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /> </linearlayout> </tabhost>
logcat:
06-19 16:25:04.175: e/androidruntime(16791): fatal exception: main 06-19 16:25:04.175: e/androidruntime(16791): java.lang.illegalstateexception: not execute method of activity 06-19 16:25:04.175: e/androidruntime(16791): @ android.view.view$1.onclick(view.java:3603) 06-19 16:25:04.175: e/androidruntime(16791): @ android.view.view.performclick(view.java:4103) 06-19 16:25:04.175: e/androidruntime(16791): @ android.view.view$performclick.run(view.java:17117) 06-19 16:25:04.175: e/androidruntime(16791): @ android.os.handler.handlecallback(handler.java:615) 06-19 16:25:04.175: e/androidruntime(16791): @ android.os.handler.dispatchmessage(handler.java:92) 06-19 16:25:04.175: e/androidruntime(16791): @ android.os.looper.loop(looper.java:137) 06-19 16:25:04.175: e/androidruntime(16791): @ android.app.activitythread.main(activitythread.java:4744) 06-19 16:25:04.175: e/androidruntime(16791): @ java.lang.reflect.method.invokenative(native method) 06-19 16:25:04.175: e/androidruntime(16791): @ java.lang.reflect.method.invoke(method.java:511) 06-19 16:25:04.175: e/androidruntime(16791): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 06-19 16:25:04.175: e/androidruntime(16791): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 06-19 16:25:04.175: e/androidruntime(16791): @ dalvik.system.nativestart.main(native method) 06-19 16:25:04.175: e/androidruntime(16791): caused by: java.lang.reflect.invocationtargetexception 06-19 16:25:04.175: e/androidruntime(16791): @ java.lang.reflect.method.invokenative(native method) 06-19 16:25:04.175: e/androidruntime(16791): @ java.lang.reflect.method.invoke(method.java:511) 06-19 16:25:04.175: e/androidruntime(16791): @ android.view.view$1.onclick(view.java:3598) 06-19 16:25:04.175: e/androidruntime(16791): ... 11 more 06-19 16:25:04.175: e/androidruntime(16791): caused by: android.content.activitynotfoundexception: unable find explicit activity class {com.example.loginscreen/com.example.loginscreen.linktabs}; have declared activity in androidmanifest.xml? 06-19 16:25:04.175: e/androidruntime(16791): @ android.app.instrumentation.checkstartactivityresult(instrumentation.java:1541) 06-19 16:25:04.175: e/androidruntime(16791): @ android.app.instrumentation.execstartactivity(instrumentation.java:1416) 06-19 16:25:04.175: e/androidruntime(16791): @ android.app.activity.startactivityforresult(activity.java:3351) 06-19 16:25:04.175: e/androidruntime(16791): @ android.app.activity.startactivityforresult(activity.java:3312) 06-19 16:25:04.175: e/androidruntime(16791): @ android.app.activity.startactivity(activity.java:3522) 06-19 16:25:04.175: e/androidruntime(16791): @ android.app.activity.startactivity(activity.java:3490) 06-19 16:25:04.175: e/androidruntime(16791): @ com.example.loginscreen.mainactivity.login(mainactivity.java:40) 06-19 16:25:04.175: e/androidruntime(16791): ... 14 more
your error message is:
unable find explicit activity class {com.example.loginscreen/com.example.loginscreen.linktabs}; have declared activity in androidmanifest.xml?
the reply question obvious: there no <activity name=".linktabs"/>
tag in manifest. add together , should work.
android android-activity
Comments
Post a Comment