[android-developers] Re: Functional retrieval of strings?
Let me get this straight - you would rather have a runtime exception that you just catch and ignore than a compile time error that will quickly identify your problem and allow you to fix it on the spot? Why exactly would you prefer this? I want to change the behavior of my app by means of the presense or absence of some items in strings.xml. This allows me to control this behavior by simply adding or deleting the items, and then clicking the Save icon in Eclipse (which automatically rebuilds). This allows me to quickly test certain features during development. Java doesn't have an equivalent to the C preprocessor. In C, I sometimes put sections of code within #ifdef blocks and change the program's behavior during development by commenting out or uncommenting certain #define lines in a header file. I would do this early in my app's development process. Later, once I was more sure about the structure of my app, I'd dispense with this procedure. Yes, I know that there are other ways to achieve this same purpose. I was just wondering if I could make use of the method I outlined. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: Functional retrieval of strings?
Resources has getIdentifier() for this. However, this is significantly less efficient than just using the R static data member. Use it if you have to (and cache the lookups), but avoid compile errors doesn't strike me as a great reason to do so. Thank you. As I described in more detail in my previous reply, I want to utilize this method of resolving certain identifiers during development. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: [android-developers] Re: Functional retrieval of strings?
On Fri, Mar 19, 2010 at 3:53 AM, HippoMan hippo.mail...@gmail.com wrote: I want to change the behavior of my app by means of the presense or absence of some items in strings.xml. This allows me to control this behavior by simply adding or deleting the items, and then clicking the Save icon in Eclipse (which automatically rebuilds). This allows me to quickly test certain features during development. Interesting. Personally, I would just use static constants ... but that's just me. Good luck. - TreKing - Chicago transit tracking app for Android-powered devices http://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: Functional retrieval of strings?
If you want to 'dynamically' load these strings, you probably could use reflection. Some 'pseudo' code: public String somehowGetStringAnotherWay(Resources res, String stringName) { try { Field stringField = R.string.class.getField(stringName); int stringID = stringField.getInt(null); return res.getString(stringID); } catch (Exception e) { return null; } } However, doing this to 'avoid compilation errors' does not sound like a good idea... On Mar 18, 9:49 pm, HippoMan hippo.mail...@gmail.com wrote: I know that I can retrieve a string within an Activity as follows: this.getString(R.string.foobar) (assuming that I have previously defined a string named foobar). However. I'm wondering if there also might be an alternate way to retrieve this same string in a functional manner, without an explicit attribute reference. I'm talking about something like this: this.somehowGetStringAnotherWay(foobar) The reason I'd like this is so I can avoid compile errors if the string doesn't exist. This would allow me to do something like the following: String foobar = null; try { foobar = this.somehowGetStringAnotherWay(foobar);} catch (SomeSortOfException e) { Log.e(MyActivity, foobar string not found); } Is there any way I can do this? Thanks in advance. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: Functional retrieval of strings?
For one thing, it allows you to alter the behavior depending on the device characteristics. It also is also easier to script such changes, via XSLT. And it's one way pulling these configurable pieces into a single location. Of course, a dedicated class accomplishes this. It doesn't sound like he's taking advantage of any of these, but it's worth noting the advantages anyway. I've also done it with an XML resource, for things a bit too complicated to describe with simple strings. On Mar 19, 6:52 am, TreKing treking...@gmail.com wrote: On Fri, Mar 19, 2010 at 3:53 AM, HippoMan hippo.mail...@gmail.com wrote: I want to change the behavior of my app by means of the presense or absence of some items in strings.xml. This allows me to control this behavior by simply adding or deleting the items, and then clicking the Save icon in Eclipse (which automatically rebuilds). This allows me to quickly test certain features during development. Interesting. Personally, I would just use static constants ... but that's just me. Good luck. --- -- TreKing - Chicago transit tracking app for Android-powered deviceshttp://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: Functional retrieval of strings?
I'd suggest instead true/false as the string values. It simplifies your code and gives you the same result. On Mar 19, 1:53 am, HippoMan hippo.mail...@gmail.com wrote: Let me get this straight - you would rather have a runtime exception that you just catch and ignore than a compile time error that will quickly identify your problem and allow you to fix it on the spot? Why exactly would you prefer this? I want to change the behavior of my app by means of the presense or absence of some items in strings.xml. This allows me to control this behavior by simply adding or deleting the items, and then clicking the Save icon in Eclipse (which automatically rebuilds). This allows me to quickly test certain features during development. Java doesn't have an equivalent to the C preprocessor. In C, I sometimes put sections of code within #ifdef blocks and change the program's behavior during development by commenting out or uncommenting certain #define lines in a header file. I would do this early in my app's development process. Later, once I was more sure about the structure of my app, I'd dispense with this procedure. Yes, I know that there are other ways to achieve this same purpose. I was just wondering if I could make use of the method I outlined. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.