android - setOnClickListener error - cannot resolve symbol -
i want create button which, when clicked, show intent.
this code:
<button android:text="bine ati venit!" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/button1" android:background="#479fc7" android:textsize="40dp" android:textcolor="@color/colorprimarydark" android:textstyle="normal|bold|italic" android:textallcaps="false" android:fontfamily="casual" android:onclick="next_page"/>
and .java class:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_welcome); } button button = (button) findviewbyid(r.id.button1); button.setonclicklistener( new view.onclicklistener() { public void onclick (view v){ next_page(v); } }); public void next_page(view v) { intent intent = new intent(this, mapsactivity.class); startactivity(intent); }
i errors: "cannot resolve symbol 'setonclicklistener'", "variable onclick never used", "; expected"....
you either declare onclick attribute method name in xml or programaticaly set in oncreate method.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_welcome); button button = (button) findviewbyid(r.id.button1); button.setonclicklistener( new view.onclicklistener() { public void onclick (view v){ next_page(v); } }); } public void next_page(view v) { intent intent = new intent(this, mapsactivity.class); startactivity(intent); }
Comments
Post a Comment