How to Handle Two Activities with Two layouts in android -
in android application have 2 activities.
one gmapsactivity
, 1 gmapsactivity1
, 2 layouts login.xml
, main.xml
by default want load login.xml
, in want call main.xml
on different conditions of password. when call gmapsactivity1
application crashed. here code sample gmapsactivity
public class gmapsactivity extends mapactivity { edittext password; button login; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.login); password=(edittext)findviewbyid(r.id.pass); login=(button)findviewbyid(r.id.logbtn); login.setonclicklistener(new view.onclicklistener(){ public void onclick(view v) { intent myintent = null; if(password.gettext().tostring().equals("admin")) { myintent = new intent(getapplicationcontext(), gmapsactivity.class); startactivity(myintent); } else { toast.maketext(getbasecontext(), "invalid password - try again", toast.length_short).show(); } } }); } @override protected boolean isroutedisplayed() { return false; } }
how solve this?
okay have
gmapsactivity.java login.xml
, gmapsactivity1 main.xml
first of change manifeste this
<application android:icon="@drawable/icon" android:label="@string/app_name" > <activity android:name=".gmapsactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" > <category android:name="android.intent.category.launcher" > </category> </action> </intent-filter> </activity> <activity android:name=".gmapsactivity1" android:label="@string/app_name" > <intent-filter> <category android:name="android.intent.category.launcher" > </category> </intent-filter> </activity> </application>
then gmapsactivity.java should this
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.login); //..some code here.. } @override public void onclick(view v) { intent = new intent(gmapsactivity.this, gmapsactivity1.class); startactivity(i); }
and gmapsactivity1.java should this
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); //..some code here.. }
also may check below simple tutorial understand
start/load activity activity in android
still have doubt, let me know!!
Comments
Post a Comment