Android widgets are included into a layout just as the views and view groups that we have been previously using. Although each widget has its own unique characteristics, they all inherit from the View class.
Here we will insert a CheckBox widget but use a callback from the parent class to edit its properties.
Drag-and-drop a CheckBox from the Form Widget palette onto the default layout, as seen in the next screenshot:
Open the main.xml tab and edit the new element so that it has the following properties:
<CheckBox android:text="A CheckBox" android:id="@+id/check_box" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Include the following code inside the main Java activity's
onCreate()
method:CheckBox checkBox = (CheckBox) findViewById(R.id.check_box); checkBox.setOnClickListener(new OnClickListener...