Reusing layout XML and the code behind

后端 未结 2 489
无人及你
无人及你 2020-12-09 10:50

I am trying to turn a couple buttons into a reusable component in Android. I have successfully gotten the XML / UI portion working, but I can\'t figure out how to make code

2条回答
  •  借酒劲吻你
    2020-12-09 11:05

    By using in XML layout, you're making only the layout reusable, not any Java code that uses it.

    You must create a subclass of View, if you want to reuse Java logic as well. The tutorial from your link has a sample that fits your need very well:

    public class OkCancelBar extends LinearLayout {
    ...
    

提交回复
热议问题