java - Added methods to the Button (any view Class) in Android -


this question has answer here:

i have set android class programmaticly set text of series button created in xml. in class create identifier(numberid) each instance of button later used in onclick method able tell apart each button , have differences both.

i have used below code , have set buttons in xml use class instead of official button class

public final class numpadbutton extends button { public int buttonnumber;  public numpadbutton(context context) {     super(context);      }   public void setbuttonnumber(int buttonnumber) {     this.buttonnumber = buttonnumber;  }  public int getbuttonnumber() {     return buttonnumber; } 

}

however extending button class , adding required methods ends causing error : android.view.inflateexception: binary xml file line #13: error inflating class...

i know there may other solutions , open suggestion best way accomplish goal, interested in figure out how make way talked above work too.

edit: xml

<macintyre.math.com.mathpractice.numpadbutton style="@style/button" /> 

the style, although don't see why causing problems.

 <style name="button">         <item name="android:layout_width"> fill_parent</item>         <item name="android:layout_height">fill_parent</item>         <item name="android:layout_weight"> 1</item>     </style>    06-02 02:42:32.625    2428-2428/macintyre.math.com.mathpractice w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0xa4d56b20) 06-02 02:42:32.629    2428-2428/macintyre.math.com.mathpractice e/androidruntime﹕ fatal exception: main     process: macintyre.math.com.mathpractice, pid: 2428     android.view.inflateexception: binary xml file line #13: error inflating class macintyre.math.com.mathpractice.numpadbutton             @ android.view.layoutinflater.createview(layoutinflater.java:603)             @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:696)             @ android.view.layoutinflater.rinflate(layoutinflater.java:755)             @ android.view.layoutinflater.rinflate(layoutinflater.java:758)             @ android.view.layoutinflater.parseinclude(layoutinflater.java:839)             @ android.view.layoutinflater.rinflate(layoutinflater.java:745)             @ android.view.layoutinflater.inflate(layoutinflater.java:492)             @ android.view.layoutinflater.inflate(layoutinflater.java:397)             @ macintyre.math.com.mathpractice.numberpad.oncreateview(numberpad.java:28)             @ android.app.fragment.performcreateview(fragment.java:1700)             @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:866)             @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1040)             @ android.app.fragmentmanagerimpl.addfragment(fragmentmanager.java:1142)             @ android.app.activity.oncreateview(activity.java:4786)             @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:689)             @ android.view.layoutinflater.rinflate(layoutinflater.java:755)             @ android.view.layoutinflater.inflate(layoutinflater.java:492)             @ android.view.layoutinflater.inflate(layoutinflater.java:397)             @ macintyre.math.com.mathpractice.additionfragment.oncreateview(additionfragment.java:19)             @ android.app.fragment.performcreateview(fragment.java:1700)             @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:890)             @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1062)             @ android.app.backstackrecord.run(backstackrecord.java:684)             @ android.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1447)             @ android.app.fragmentmanagerimpl$1.run(fragmentmanager.java:443)             @ android.os.handler.handlecallback(handler.java:733)             @ android.os.handler.dispatchmessage(handler.java:95)             @ android.os.looper.loop(looper.java:136)             @ android.app.activitythread.main(activitythread.java:5001)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601)             @ dalvik.system.nativestart.main(native method)      caused by: java.lang.nosuchmethodexception: <init> [class android.content.context, interface android.util.attributeset]             @ java.lang.class.getconstructorormethod(class.java:472)             @ java.lang.class.getconstructor(class.java:446)             @ android.view.layoutinflater.createview(layoutinflater.java:568)             at android.view.layoutinflater.createviewfromtag(layoutinflater.java:696)             at android.view.layoutinflater.rinflate(layoutinflater.java:755)             at android.view.layoutinflater.rinflate(layoutinflater.java:758)             at android.view.layoutinflater.parseinclude(layoutinflater.java:839)             at android.view.layoutinflater.rinflate(layoutinflater.java:745)             at android.view.layoutinflater.inflate(layoutinflater.java:492)             at android.view.layoutinflater.inflate(layoutinflater.java:397)             at macintyre.math.com.mathpractice.numberpad.oncreateview(numberpad.java:28)             at android.app.fragment.performcreateview(fragment.java:1700)             at android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:866)             at android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1040)             at android.app.fragmentmanagerimpl.addfragment(fragmentmanager.java:1142)             at android.app.activity.oncreateview(activity.java:4786)             at android.view.layoutinflater.createviewfromtag(layoutinflater.java:689)             at android.view.layoutinflater.rinflate(layoutinflater.java:755)             at android.view.layoutinflater.inflate(layoutinflater.java:492)             at android.view.layoutinflater.inflate(layoutinflater.java:397)             at macintyre.math.com.mathpractice.additionfragment.oncreateview(additionfragment.java:19)             at android.app.fragment.performcreateview(fragment.java:1700)             at android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:890)             at android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1062)             at android.app.backstackrecord.run(backstackrecord.java:684)             at android.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1447)             at android.app.fragmentmanagerimpl$1.run(fragmentmanager.java:443)             at android.os.handler.handlecallback(handler.java:733)             at android.os.handler.dispatchmessage(handler.java:95)             at android.os.looper.loop(looper.java:136)             at android.app.activitythread.main(activitythread.java:5001)             at java.lang.reflect.method.invokenative(native method)             at java.lang.reflect.method.invoke(method.java:515)             at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785)             at com.android.internal.os.zygoteinit.main(zygoteinit.java:601)             at dalvik.system.nativestart.main(native method) 

elements inflated layout file use 2nd constructor signature:

public numpadbutton(context context, attributeset attrs) 

although should implement constructor signatures:

public numpadbutton(context context, attributeset attrs, int defstyleattr) public numpadbutton(context context, attributeset attrs, int defstyleattr, int defstyleres) 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -