Manipulating View Components

One of the key pillars of the Vapor Android framework is that it gives you a fluent interface for working with Android Views, allowing you to create chains of method calls at will - just like you would in jQuery.

Related Type Hierarchies

Achieving fluency in a strongly typed language such as Java requires use of generic parameters so that we don't lose type information when using inherited methods. We use related type hierarchies in order to hides these generics, and keep the Vapor Android framework easy to use.

Vapor___<T extends ___,?> Types

Types in this hierarchy, starting from VaporView<? extends View,?>, are the equivalent fluent Vapor companions to Android types.

For instance, VaporTextView is the Vapor companion for the Android TextView type.

Indeed this simple naming convention is employed across all companion types in the framework, making it easy to work out the correct Vapor type to use for any given Android View type.

These types provide the fluent View methods that you will use in your Vapor code to interact with Android View components. You probably won't need to use this family of types directly however, as often the alias V types described below are sufficient and easier to use.

V___<T extends ___> Types

Every VaporView type has a direct alias V type.

On the whole, V types only have one generic parameter, the Android type that it encapsulates. This is allowed to be any type derived from the companion Android type. For example, VaporTextView<T extends TextView> can accept any T that extends the Android TextView.

This design was intentional as it allows you to use the Vapor View classes in conjunction with your own custom derived Android View types seamlessly.

MultiSelectors (VaporX)

All VaporViews have a companion VaporX type that allows for multiple VaporView instances to be controlled and manipulated at once, similar to jQuery selectors. This is discussed in detail in the VaporX section which is highly recommended reading.

The powerful VaporX framework keeps your Android app code compact, and even allows you to apply custom code on the members of the underlying group (described below).

If you are not grouping VaporView components of the same class, you must use the Vapor companion for the most specific Android class that they all have in common. For example VaporXTextView would be used to group TextView's and Button's together, as VaporTextView is the most specific class they have in common.

Selector Types

Any combination of the following types can be used to instantiate a VaporXView:

  • self - A VaporView instance that can be safely treated as an instance of the type being instantiated
  • T - Any instance that can be safely treated as an instance of T
  • int/Integer - An id that can be safely loaded from the content view as an instance of T

VaporX___<T extends ___,?> Types

In the VaporX framework every VaporView type has a companion VaporXView type that provides a superset of the API, adding new methods that are applicable to managing related components simultaneously.

Read the VaporX section to see how VaporXView behaviour differs from that of a singular VaporView.

VX___<T extends ___> Types

Further, every VaporXView type has a companion VX type. The VX is purely an alias type that takes care of filling in some of the ugly generic class parameters required for a fluent architecture.

The VX types are therefore much easier to work with!