Counters are external objects that can be created by the toolkit using XML definition files, which are stored outside of the system. Counters created from external definitions through ElementFactory are static and you need to declare them at installation or configuration time. Besides using external definition files to create counters, you can also dynamically create counters during the runtime of the application.
Following is an example of a counter declaration in the XML file:
You must instantiate the counter before use. A counter that is based on the XML file is instantiated automatically when reading it from the file.
To instantiate a dynamic counter and its counter elements that are not defined in an XML file, you need to use the default counter constructor. Following is an example:
Counter counter = new Counter(); counter.setIncreaseMaxLimit(1000f); counter.setTotalMaxLimit(10000f); counter.setIncreaseTimesMaxLimit(100);
You can also initiate the same counter as previous through the following constructor:
The function of counter is to keep track of numeric values, every time you want to update a value through a counter you can invoke the following API:
counter.increase(float value);
This operation will add the increase value to total element of the counter, and plus one to increase time. Then you can check the current total value and increase times through the following two APIs:
counter.currentTotal(); //retrieve current total value. counter.increaseTimes(); //retrieve increase times value.