sdk - android process crash on adb with simple app, not sure what i'm doing wrong -
package com.russell.saw; import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.button; public class learnandroid extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); button landroid_button = (button) findviewbyid(r.id.landroid_button); { landroid_button.setonclicklistener( new view.onclicklistener() { public void onclick(view v) { // todo auto-generated method stub setcontentview(r.layout.button); } }); } button back_button = (button) findviewbyid(r.id.back_button); { back_button.setonclicklistener( new view.onclicklistener() { public void onclick(view v) { // todo auto-generated method stub setcontentview(r.layout.main); } }); } } }
i'm unsure of going wrong, it's simple learning tester app, 2 buttons, going 1 page another, crash run on phone.
woah! have onclicklisteners set wrong. calling setcontentview
in onclicklisteners. instead, need use intent go 1 activity next. needs this:
mybutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent intent = new intent(main.this, myotheractivity.class); startactivity(intent); } });
also, don't use landroid_button
reference button: that's xml id of resource. instead need grab hold of button doing this:
button mylandroidbutton = (button)findviewbyid(r.id.landroid_button)
then when set onclicklistener, use variable: mylandroidbutton
mylandroidbutton.setonclicklistener
, on..
Comments
Post a Comment