I’m new to Android(and Java also) and I’m trying to understand what are Fields in predefined Android classes.
For example in the Android View class there are Fileds: EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET etc.
Please can you tell me how to understand this and how can I use it? For me it looks like some constants but it’s not.
Typically they are constants for the class, to be used in situations like this:
They usually have integer values, but they make the code more readable this way, and also allow for later changes to the API without altering the behavior of previous code. (
Widgets.BLACK_AND_TAN == 7, orWidgets.BLACK_AND_TAN ==15,could both be true, or any other number. It doesn’t matter. Just thatBLACK_AND_TANalways corresponds to Black and Tan coloring.)edit: note that Widget is a made up class, as is the
BLACK_AND_TANconstant. let me get a real example for you.Real Example, used to re-position the cursor every time a text field is updated:
Note that these do not HAVE to be constants as we normally refer to them; for example
can be user defined, but it does specify how long a toast should display