A constant variable is a variable that will not change during the execution of the code.
Java does not directly support constants. However, a static final variable is effectively a constant.
1.Add the following line to add a private constant integer variable in the class level. Use final modifier which combined with static modifier. The final modifier indicates that the value of this field cannot change. The static modifier causes the variable to be available without loading an instance of the class where it is defined. The final modifier causes the variable to be unchangeable. Although these aren't syntactical rules, they are widely used as accepted conventions. Java constants are normally declared in ALL CAPS. Underscores normally separate Words in Java constants.
private static final int DATE_PICKER_DIALOG = 0;
2. Compile and run!
Resources:
http://kodejava.org/how-do-i-define-a-constant-variable/
http://www.tech-faq.com/how-to-declare-a-constant-in-java.html
Popular Posts
- Perform an Action after Enter keypress on EditText
- Intent setType(String type) - How to Set an Explicit MIME data type
- Determine the Hex value for a color
- android:scrollbarStyle - Change the Scrollbar Location/Style in a TextView
- How to Register an Activity that Responds to NFC tags for URI's that point to a URL
- android:ellipsize - Add an ellipsis(...) in a TextView
- Solution: Running Android Lint has encountered a problem Failed
- How to Set Permission for I/O Operations over NFC
- How to Install an SDK package
- android:drawablePadding - Add Padding to a Drawable in a TextView, in XML