java - setOnClickListener is not recognised by Android Studio -
this question has answer here:
- button.setonclicklistener. error 2 answers
when try open new activity button, setonclicklistener not work. reason, android studio not recognise it.
we attempting open new activity when button pressed (but haven't coded bit yet).
we grateful help!
the problem cannot call next.setonclicklistener()
in body of mainactivity
class; must put code inside method (probably oncreate()
).
additionally, line:
button next = (button) findviewbyid(r.id.buttonnext);
is technically ok never work (because have not yet called setcontentview()
@ point in time).
change button declaration simply
button next;
and change oncreate()
to
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); next = (button) findviewbyid(r.id.buttonnext); next.setonclicklistener(new onclicklistener() { public void onclick(view v) { startactivity(new intent(mainactivity.this, loginactivity.class)); } }); }
Comments
Post a Comment