android - Button is not clickable -
i have button "savestats" seems not accept clicking.
on emulator there no animation of clicking.
i have tried clean , restart eclipse, didnt work.
i have checkbox widget works fine, button dont work. here code:
thank helping :)
button savestats; checkbox agecheck, heightcheck, weightcheck, fatcheck; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.set_personal_data); savestats = (button) findviewbyid(r.id.savestats); agecheck = (checkbox) findviewbyid(r.id.checkboxage); heightcheck = (checkbox) findviewbyid(r.id.checkboxheight); weightcheck = (checkbox) findviewbyid(r.id.checkboxweight); fatcheck = (checkbox) findviewbyid(r.id.checkboxfat); savestats.setonclicklistener(this); agecheck.setonclicklistener(this); heightcheck.setonclicklistener(this); weightcheck.setonclicklistener(this); fatcheck.setonclicklistener(this); } public void onclick(view v) { // todo auto-generated method stub switch(v.getid()){ case r.id.savestats: { toast.maketext(this, "working", toast.length_long).show(); return; } case r.id.checkboxage: { if(agecheck.ischecked()) toast.maketext(this, "ok", toast.length_long).show() return; } //// //// //// ////.... button xml code:
<button android:id="@+id/savestats" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/textview1" android:text="save" />
you have implement onclicklistener() doing way
public class activityname extends activity implements onclicklistener { then override onclick()
@override public void onclick(view v) { ... } just note. way declare same click function in xml each button write function in java code. prevents needing implements onclicklistener , declaring buttons , setting onclicklistener() inside code. way depends on best option. here's little example:
in xml each button declare function
<button android:id="@+id/btn1" ... android:onclick="functionname"/> <button android:id="@+id/btn2" ... android:onclick="functionname"/> then in java code:
public void functionname(view v) { ... switch on id other way } the method needs public, accept view param, , same name declared in xml
Comments
Post a Comment