java - setOnClickListener is not recognised by Android Studio -


this question has answer here:

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).

our code

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

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -