Skip to main content
improved formatting
Source Link
MByD
  • 137.6k
  • 30
  • 269
  • 278

I've got a class that extends a button. I want to add an additional attribute to it. Is there any way to initialize that attribute from XML? For example:  

public class MyButton extends Button{ private String myValue = "";

<MyButton android:id="@+id/myBtn" myValue="Hello World"></MyButton> 

public class MyButton extends Button{ private String myValue = ""; public CalcButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } } 

}

I've got a class that extends a button. I want to add an additional attribute to it. Is there any way to initialize that attribute from XML? For example:  

public class MyButton extends Button{ private String myValue = "";

public CalcButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } 

}

I've got a class that extends a button. I want to add an additional attribute to it. Is there any way to initialize that attribute from XML? For example:

<MyButton android:id="@+id/myBtn" myValue="Hello World"></MyButton> 

public class MyButton extends Button{ private String myValue = ""; public CalcButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } } 
Source Link

Setting attributes of custom views in Android

I've got a class that extends a button. I want to add an additional attribute to it. Is there any way to initialize that attribute from XML? For example:

public class MyButton extends Button{ private String myValue = "";

public CalcButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } 

}