views:

169

answers:

4

Hi,

I am creating a resource file using

ResourceBundle _resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);

Now i want to create another Resource file in that same class.

Can i do it in the same way like for first Resource file ?

The interface ResourceFile.java is an auto-generated file. Then how to view it ?

A: 

I m able to view interface ResourceFile.java file.

ResourceFile.rrc consists of Keys & Values. From a Key I can get its value using

_resources.getString(key); 

But how to get Key ? I want to get the list of all Keys available in my resource file . How to get it ?

Shreyas
A: 

You need to edit the resource file (ResourceFile.rrc) in the BlackBerry JDE directly - from there you can add new key/value pairs. I don't think there's a way to iterate through all available keys in the code.

Marc Novakowski
ok. But can we get the Key ? as we can get Value of the corresponding Key using "_resources.getString(key); ". can we use "_resources.getString(value);" to get the Key ?
Shreyas
You can look up a value based on a key but you can't look up a key based on a value. I'm not sure why you'd want to do this, anyway. You usually hard code the key in your code based on the generated ResourceFile.java file.You can get the list of keys (manually) by looking at your actual ResourceFile.rrc file either in the JDE or with a text editor.If you can explain the problem you're trying to solve in more detail (i.e. the need to iterate over key names) we can offer better suggestions.
Marc Novakowski
I ll get the list of Keys using a text editor as u suggested. I m getting the Key at run-time say CountryName which is a String for which I want to get the Value of that corresponding Key using "_resources.getString(key)". But that Key should be int. So how to convert that String Key to int ? That String contains a CountryName say "India"
Shreyas
In interface ResourceFile.java file which is a Derived file, int India = 78 is there. So can I get that number 78 which I can use in resources.getString(78) ?
Shreyas
Yes, just use ResourceFile.India in your code and it will pass that integer (78) into the getString() method.
Marc Novakowski
But I dont know the CountryName as it comes at runtime as String CountryName
Shreyas
It sounds like you need to be grabbing a different ResourceBundle based on the input country (or "locale"), not a different key. The key/value pairs in the bundle refer to the actual localized string values for that bundle. See the javadocs at http://java.sun.com/j2se/1.3/docs/api/java/util/ResourceBundle.html (which the BlackBerry is compatible with) for a better explanation of how to do this.
Marc Novakowski
A: 

I m looking into the APIs.

How to get String[] using "_resources.getStringArray(key)" ?

In ResourceFile.rrc , I have added like ,

     Keys                                                         Values

     Names                                               {Name1, Name2, ..........}

Now when i do

String[] names = _resources.getStringArray(ResourceFile.Names);

It gives ClasscastException.

Shreyas
A: 

In BlackBerry JDE 4.5.0 API docs, net.rim.device.api.i18n Class ResourceBundle

Its written that

Compatible with java.util.ResourceBundle in Java's standard edition.

which is having "abstract Enumeration getKeys() "

So can we use it in Blackberry 4.5 ? If yes then how to use it?

Shreyas