2

As you know you can write whatever resource you need inside res/values. I made an xml file for each gui/activity I'm using. Here's an example:

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">This is home!</string>
    <string name="app_name">Hattrick4Manager</string>
    <string name="oauth_button">Authorize me!</string>
    <string name="download_button">Syncronize</string>
    <string name="oauth_name">Authorization</string>
</resources>

update-ui.xml

<resources>
        <string name="inizio_download">Update Started...</string>
        <string name="fine_download">Update Completed...</string>
        <string name="update_title">Update</string>
        <string name="update_done">Done</string>
        <string name="update_inizio_club">Club...</string>
        <string name="update_inizio_arena">Arena...</string>
        <string name="update_inizio_fan">Fans...</string>
        <string name="update_inizio_matches">Matches...</string>
        <string name="update_inizio_league">League...</string>
        <string name="update_inizio_leaguefix">League Fixtures...</string>
        <string name="update_inizio_economy">Economy...</string>
        <string name="update_inizio_players">Players...</string>
</resources>

When I use this in the code I have to recall them like:

R.string.update_done

or

R.string.hello

my problem is that like this I have basically to add the prefix for every GUI I make. I would prefer doing something like:

R.string.update-ui.done

Is it possible?

5
  • No answer, just a question. What should happen if the text "Done" does exist on several activities? Do you want to put it in dozens of files? And what about the translated text? I don't like your approach. Done is Done. Give it the name done and use it in one central strings.xml. Just my 2 cents. Commented Aug 21, 2011 at 18:18
  • Well, "Done" could not have different semantics because the word is pretty clear but the way I would like to express "Done" could be different. In my case I have in my update-ui "Done" -> "Update Completed" and I could also have in the arena-ui "Done" -> "Building seats completed" Commented Aug 21, 2011 at 18:53
  • I do not understand that. The text is 'Done', right? On both activities? What's the problem? If you need to create different semantics use name="updatecompleted" with text="Done" and name="buildingseatscompleted" with text "Done". It's an old discussion what label to use. I prefer to use the label close to the text and not close to the activity/package/... Commented Aug 22, 2011 at 13:41
  • I'm sorry I was thinking about the label "Done", not the text inside it. Of course I do not want to do that for redundancy, I want to do that to keep labels separated when I'm programming. To me it's more natural to write R.string.update-ui.done instead of R.string.update_ui_done Commented Aug 22, 2011 at 15:54
  • Just to add something. If I have a label done="Done" then that would go under R.string.general-ui.done, I'm not repeating that twice. Commented Aug 22, 2011 at 16:00

1 Answer 1

2

You can create as many resource files as you want, but you can not perform the nested name referencing based on the filename: the Android aapt tool doesn't support arbitrary nested objects on the generated R object.

You might be able to do stuff like this in update-ui.xml:

<resources>
        <string name="update_ui_inizio_download">Update Started...</string>
        <string name="update_ui_fine_download">Update Completed...</string>
</resources>

and then use

R.string.update_ui_inizio_download

to reference the contents of the file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.