Home and Learn: Android Course
We'll now add some check boxes to our app from the previous lesson. We'll add three of them. These will be things you can buy. You can buy none, one, two, or all three items. The price for the items will then appear in the display area at the top. Let's make a start.
We can add the checkboxes to a vertical linear layout. In the Palette to the left of Android Studio, drag a Linear Layout (vertical) from the Layouts category onto the Component Tree, just under your Radio Buttons. Locate the CheckBox control in the Palette. It can be found under the Buttons category:

Drag three of these onto your Linear Layout. We'll position them in a moment. First, though, select each checkbox in turn and set the Text and ID Atrributes as follows (you can select a checkbox in the Component Tree):
Checkbox One
Text: Java Course - £30
ID: checkboxJava
Checkbox Two
Text: Android Course - £20
ID: checkboxAndroid
Checkbox Three
Text: C# NET Course - £10
ID: checkboxCSharp
By default, the checkboxes will end up in the top left of your layout. So, with the Linear Layout selected, use the square sizing handles, and drag to somewhere in the middle. Then add a constraint from the top middle round circle of the Linear Layout to the bottom middle circle of the RadioGroup widget. Add other constraints to the left, right, and bottom, and your Linear Layout will look something like this (but don't worry if it doesn't):

Your Component Tree should look like this:

Now let's do some coding for checkboxes. We'll do that in the next lesson below.
< Radio Button Code| Android Checkbox Code >
Back to the Android Contents Page
Email us: enquiry at homeandlearn.co.uk