Vaibhav Mishra Vaibhav Mishra - 5 months ago 26
Android Question

Android compound button through xml file

I am trying to use android's built in control

CompoundButton
, however I have no luck using it in xml, here is my code

<CompoundButton
android:id="@+id/mini_recorder_play"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@drawable/play_d" />


it is throwing exception while inflating.

Answer

CompoundButton is an abstract class, you cannot instantiate it directly. You must either instantiate one of its subclasses (e.g. CheckBox, RadioButton, ToggleButton) or create your own customized subclass if none of those widgets fits your needs.

HTH