Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
In this lesson we'll stick to Java and not pay attention to XML just yet.
Most classes used are Android classes.
Button for example is not a java.awt.Button, but an android.widget.Button.
To have something that a user can do, we extend Activity.
When it's being created, its onCreate method is called.
Here we use the simplest layout, LinearLayout.
Controls added will be adjusted vertically and the layout's colour is set to green. FF00FF00 means : not transparent(FF), no red(00), full green(FF), no blue(00).
The Button is added to the layout, which derives from ViewGroup, making it a container.
The LinearLayout is then set as the Activity's content.
When the button is pushed, this is what happens,...
because that's what the anonymous OnClickListener does.
Each click, the LinearLayout's colour is changed,...
based on some random numbers.
And a tiny message is shown as a simple way to provide feedback to the user. This can also come in handy as an aid to our development efforts.
The colour is created as follows : 255 for not transparent, 0-255 for red, 0 no green, 128-255 for blue.