Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

So, I have a string array of some random saying and the like, but I would like to be able to do something different some of them, such as open a URL. I've been racking my brain trying to come up with the best way to do this. I want the ability to add new things, remove some, without having to worry about touching my code, unless perhaps there was a new action or something. The best possible thing I could think of would be to somehow have a multiple dimension string array, so that I can use the strings in the first column, and the action from the second column. Is there a way to do this?

Alternatively, is there a better way to do what I want?

share|improve this question
up vote 1 down vote accepted

Is there a way to do this?

No, sorry. Moreover, IMHO, it does not fit your described data model, as "I can use the strings in the first column, and the action from the second column" to me describes two independent string arrays. It may be that I am misinterpreting you, though.

Alternatively, is there a better way to do what I want?

If you really do have a dependency between the "columns" (i.e., for each string in the "first column" there is a distinct and largely unique set of actions from the "second column"), use an XML resource in res/xml/, with a structure like:

<stuff>
  <thing name="foo">
    <action>something</action>
    <action>or</action>
    <action>another</action>
  </thing>

  <thing name="bar">
    <action>have</action>
    <action>whatever</action>
    <action>you</action>
    <action>need</action>
  </thing>
</stuff>

If you need to internationalize the strings, just have separate translations in the XML (e.g., res/xml/, res/xml-es/, res/xml-zh).

share|improve this answer
    
I've been needing to learn XML for some time. I was hoping there would be an easier way, but I decided to go ahead and take the plunge. So far, it looks good. Thanks for the help! – PearsonArtPhoto Mar 17 '12 at 20:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.