Changes

Jump to: navigation, search

MAP524/DPS924 Lecture 4

1,962 bytes added, 20:42, 12 July 2015
RelativeLayout
This layout also can be used to create pretty much any imaginable layout, but I find it much harder to maintain.
 
= Views =
 
Depending on how advanced your application is you may need to make your own views, but in most cases you'll be able to work with the existing ones.
 
All these views are usually defined in your layout XML file, and most of them will be controlled in some way from code. In the last lecture we saw how to get a reference to an XML-defined element in your java code.
 
* TextView: Used to show text. Can change attributes like the text size and colour. Can't be used for complex text but can be made to contain clickable links.
* Button: obvious enough.
* CheckBox: obvious enough. Can be [un]checked from code at any time.
* RadioButton: When you want it to work like a real radio button you need to add more than one to a RadioGroup. See [http://developer.android.com/guide/topics/ui/controls/radiobutton.html the documentation].
* EditText: Like the AutoCompleteTextView you used in the last lab, but without the auto complete feature. Can be made read only, be restricted to one line, and using the addTextChangedListener callback you can do very interesting things. Also note by changing android:inputType you can change the keyboard that's presented to the user.
* ImageView: Show an image from your resources (or the Android resources). Use the an android:src attribute to set the source of the image.
* ProgressBar: By default isn't actually a bar, it's a spinning wheel. To make real use of it you really need something running in the background (a thread or AsyncTask). See [http://developer.android.com/reference/android/widget/ProgressBar.html the documentation].
* NumberPicker: Lets the user choose a number. Needs to be configured in java before it works to have a minimum and maximum value using setMinValue() and setMaxValue().
* Spinner: Like the number picker but with any strings as values to pick from. You'll need an Adapter similar to the one you used with the AutoCompleteTextView in the last lab, otherwise it will show nothing.

Navigation menu