Its Quite a View

All widgets, including the ones shown above, extend View, and as such give all widgets an array of useful properties and methods beyond those already described.

Useful Properties

Some of the properties on View most likely to be used include:

• Controls the focus sequence:

• android:nextFocusDown

• android:nextFocusLeft

• android:nextFocusRight

• android:nextFocusUp

• android:visibility, which controls whether the widget is initially visible

• android:background, which typically provides an RGB color value (e.g., #00FF00 for green) to serve as the background for the widget

Useful Methods

You can toggle whether or not a widget is enabled via setEnabled() and see if it is enabled via isEnabled(). One common use pattern for this is to disable some widgets based on a CheckBox or RadioButton selection.

You can give a widget focus via requestFocus() and see if it is focused via isFocused(). You might use this in concert with disabling widgets as mentioned above, to ensure the proper widget has the focus once your disabling operation is complete.

To help navigate the tree of widgets and containers that make up an activity's overall view, you can use:

• getParent() to find the parent widget or container

• getPa rentOfType () to search upwards in the tree to find a container of a certain class (e.g., find the RadioGroup for a RadioButton)

• findViewById() to find a child widget with a certain ID

• getRootView() to get the root of the tree (e.g., what you provided to the activity via setContentView())

Self Publishing

Self Publishing

Have you always wanted to write your own book and get it published? Discover How to Write, Print Sell Your Own Book! Have you always wanted to write your own book and get it published? If you have written a book or even if you have a yen to be a writer, you are probably already aware of the competition in the writing field.

Get My Free Ebook

Post a comment