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
- android:ellipsize - Add an ellipsis(...) in a TextView
- android:textColorHighlight - Set the Color of Highlighted Text in an EditText
- Perform an Action after Enter keypress on EditText
- How to Register an Activity that Responds to NFC tags for URI's that point to a URL
- How to Import a Library
- android:alpha - Set the Opacity/Transparency of Text in TextView/EditText
- Save LogCat to a Text File
- How to Set Permission for I/O Operations over NFC
- android:drawablePadding - Add Padding to a Drawable in a TextView, in XML
- String.valueOf - How to Convert a Double to a String