Is it possible to append a value to R.string or any resource under R.?

by David » Sat, 24 Oct 2009 10:01:51 GMT


Sponsored Links
 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.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Resource Alias not resolving

I'm hoping there is an answer to my problem.  I've created two sets of
graphics for my app.  A set for medium res phones and a set for high
res phones.  I've placed them into their drawable-mdpi and drawable-
hdpi folders.

I've now learned that the Dell Streak identifies itself as a large-
mdpi display.  I've created a drawable-large folder and placed the
high res images into it.  Its so far, everything is working in the
emulator.

My problem is I would like to create a single set of high res graphics
and have it availalbe to both drawable-hdpi and drawable-large.  I've
tried using the example in the docs
http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources

but it doesn't seem to work.  I wanted to use drawable-hdpi to store a
single copy of all the high res images, and store the xml aliases in
drawable-large.  It compiles without error, but when my app tries to
read the drawable, it throws an error, Null Pointer Exception.

Does the alias xml file only work with images in drawable, or can they
be in a drawable-hdpi folder?  When I try to pull the file from
drawable-hdpi it causes the error.

Any help would be appreciated.

Stephen

-- 

2. Yahoo Mail & Yahoo messenger has been updated to 1.01

Thank you bro ke tkp langsung sekarang

kang o rama is great rom,  try it



> 

3. Emoji Support

4. HTC EVO 4G Source Code released!!!

5. Unable to specify the bucket to Gallery3D

6. How to force App Widget in portrait mode???

7. How to force App Widget in portrait mode???