2

In my android app, I have a number of buttons in a grid (basically a 2-D array of components). When long pressing these components I need to display a string to the user, with each array location having different strings.

For an actual app where I am using this, please see :
RIFT Assistant : https://market.android.com/details?id=com.gopalshalu.rift.assistant
In the app, start up a soul tree .

Question

Is there a way to dynamically formulate the name of string, and get the strings value. Something like…

Int row = 0;
String target_string_name = “”;
for (int col=0;i<1;i++)
{
    target_string_name  = “teststring_” + row + “_” + col; // we have dynamically created the name
    How do we get the actual string value here, using string name in target_string_name variable?
}

How do we get the actual string value here, using string name in target_string_name variable?


Example

String to be displayed when pressing grid location (0,0) - Hello, test string at 0,0
String to be displayed when pressing grid location (0,1) - World!.. test string at 0,1

I have a string.xml file, with the following naming convension:

<string name=’teststring_row_column’>string contents</string>

So, for the above example, the string.xml will look like:

<string name=”teststring_0_0”>Hello, test string at 0,0</string>
<string name=”teststring_0_1”>World!... test string at 0,1</string>

Thanks in advance for your time and responses.

Gopal Nair
  • 830
  • 4
  • 7

2 Answers2

0

If I understand you correctly, I believe you're looking for getIdentifier().

Here's a demonstration of its use.

Nathan Fig
  • 14,970
  • 9
  • 43
  • 57
0

I think you might consider making use of setTag() also if you want to associate a particular piece of data with a view. I also started a Rift Calculator (never finished) and for display the spell tooltips (I assume that's what you're doing?) I just associated the tooltip data with the tag for that view.

Jason Robinson
  • 31,005
  • 19
  • 77
  • 131
  • The problem with associating the tooltip to a component is that, the tooltip changes with the "level" or ability, but the component remains the same. For example, there are 5 points that can be put in BeastMaster-Survival of the fittest ability. For each of these points, the tooltip changes in value, and in some cases, a totally different string. – Gopal Nair Jul 08 '11 at 18:37
  • When I parsed out the soul XML data I put each talent's characteristics and values in a class specifically for that, which included tooltip text (max rank, description, range, etc), and set that as the tag for the view. To get the current rank (and change the description accordingly), I just queried the current build for the rank of that talent. You may have your project set up completely differently though, so this may not be feasible. – Jason Robinson Jul 08 '11 at 18:45