On 10/24/09 5:10 PM, David wrote:
@Farproc

Ah yes, the R.xx.xx are integer constants created automatically in the
R.java file (i.e., h1=0x7f050002, h2=0x7f050003, etc.).  Now it makes
sense why constructing a string to reference them does not work.


@Jeffrey

I have a couple of questions.  I just finished reading up a bit on
resource bundles but things are still a little cloudy for me.  Would I
need to populate the 312 key:value pairs into the rb bundle?

  
yes.
If so, then what benefits does the bundle approach have over the the
ElseIf approach?  It seems that putting 312 strings (even if small)
into a resource bundle would be more memory usage than required when,
in the alternative, the one desired string could be called directly
from an ElseIf approach, albeit with more lines of code.

  
one line of code vs. 312 ... and being forced to use a 2nd way to store your resource strings.

Similar to your bundle idea, I thought about creating an XML array
with each string as a member but, again, all of the strings would be
pulled into memory to create the array when all I need is *one* of the
312 strings.  Too bad there isn't a way to dynamically construct a
reference to the R. resources . . .

  
XML is going to be heavier weight than a simple key, val mapping. btw, if they are localized strings, use resource bundle. if not, just use java.util.Properties.
Thanks for answering questions from a new Java-Android developer
coming from the PHP side of things.




On Oct 24, 7:17 am, Jeffrey Blattman <jeffrey.blatt...@gmail.com>
wrote:
  
using standard java res bundles,

textView.setText(rb.getString(desiredString));

and in your res bundle,

<desiredString1>=<value of R.string.h1>
<desiredString2>=<value of R.string.h2>
...

that is, the RB keys are the possible values of desiredString, and the
values are the proper mapping from a particular value of desired string.

On 10/23/09 6:59 PM, David wrote:



    
Screen A permits the user to input a value into an EditText field.
Screen B populates a TextView using one of the entries in strings.xml
based upon the TextView value.  For example, if the user inputs "2" on
Screen A then Screen B should populate the TextView with
R.strings.h2.  I have tried the following:
      
    
      // get the bundle extras from Screen A's intent
      Bundle extras = getIntent().getExtras();
      // pull out the value from the UserInput EditText sent from
Screen A
      Str desiredString = extras != null ? extras.getString
("UserInput") : "";
      // popluate textView with the string R.string.h + whatever the
user put on Screen A
      textView.setText(R.string.h + desiredString);
      
    
I get a "cannot resolve R.string.h resource" error message because,
evidently, the desiredString value is not appended onto R.string.h.
So, I decided to come at it from another angle:
      
    
      switch (desiredString) {
      case 1:
           textView.setText(R.string.h1);
      case 2:
           textView.setText(R.string.h2);
      . . .
      case 312:
           textView.setText(R.string.h312);
      
    
Note that you cannot switch on a string so I tried Integer.parseInt on
the string but I wind up with a blank Screen B with the switch
statement above.  It seems that the string is not turned into an int.
So, my question is twofold: (1) is it possible to append a variable
onto a R. entry and (2) if I am obliged to use the larger and uglier
switch approach, how do I turn an EditText string value into an Int
value?  Thanks.
      
--
    
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

  

--

Reply via email to