Its Quite a View

All widgets, including the ones previously shown, 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 previously mentioned, 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

• 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())

0 0

Post a comment