Following relevant examples represents usually the easiest way to find the appropriate solution in your code. In this case, you may have a look at the examples linked to on the "Sample applications"
page.
All this is above the scope of this discussion group, in fact off-topic. You should post such questions to StackOverflow, or other similar forums. This forum meant for general discussion on the platform and its services. By contrast, in StackOverflow, you get in contact with experienced programmers, who are happy to help.