How to use resource files in your blackberry app
In a previous post I gave the steps on how to add resource files to your application. In today’s discourse I will describe how to update your application to use those resource files.
They really are quite simple to use, provided that you realize the couple tricks.
Follow these steps to reference the resource file in your class.
Step 1 – include the resource interface
The magic of blackberry means that the resource files are converted into an interface and by implementing that interface on your class you get access to all the strings.
For example, my resource file is called ‘myApp.rrh’ and to include this resource file on my class, I do something like…
public class myApp extends UiApplication extends myAppResource
Trick #1 – The resource files’ interface name is an exact match to the resource file name + the key word ‘Resource’
Step 2 – include a reference to the resource
create a static variable and include it in your class…
private static ResourceBundle _res = ResourceBundle.getBundle(BUNDLE_ID,BUNDLE_NAME);
Trick #2 – BUNDLE_ID and BUNDLE_NAME are auto-generated by blackberry magic
reference your resource through the key name defined in your header file…
LabelField title = new LabelField(_res.getString(appName), LabelField.USE_ALL_WIDTH)
Step 3 – include a reference to a resource array
You can also create a resource array. In the resource editor, right click your resource and select ‘ConvertToMultipleValues’. The interface for adding values to this resource array is a bit clunky but hey “a poor craftsman blames his tools”.
You access the values through a string array…
String[] messages = _res.getStringArray(msg);
And that is about it.


