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,1I 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.
If I understand you correctly, I believe you're looking for getIdentifier().
Here's a demonstration of its use.
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.
精彩评论