Question on String Resources

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Question on String Resources

Postby rmanromga » Tue Nov 25, 2008 4:12 am

I have a question, is there a great advantage of using string resources as opposed to just using explicit strings? For example say you have a button whose xml is as follows:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <Button android:id="@+id/btn_update"
  2.  
  3. android:text="Update"
  4.  
  5. android:textColor="#ffffffff"
  6.  
  7. android:layout_width="wrap_content"
  8.  
  9. android:layout_height="wrap_content"
  10.  
  11. android:background="@drawable/un_focussed_90x31px"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


as opposed to a button whose xml is as follows:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <Button android:id="@+id/btn_update"
  2.  
  3. android:text="@string/update_label"
  4.  
  5. android:textColor="#ffffffff"
  6.  
  7. android:layout_width="wrap_content"
  8.  
  9. android:layout_height="wrap_content"
  10.  
  11. android:background="@drawable/un_focussed_90x31px"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


The difference is the "android:text" line. What is the advantage of using one over the other. i.e android:text="Update" ap opposed to using android:text="@string/udpate_label" (where we would have a String resource with the label 'update_label' in the Strings.xml file)

Thanks,
--D
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Top

Postby MrSnowflake » Tue Nov 25, 2008 11:33 am

The main reason for using String resources is i18n (internationalisation). When you use string literals, you have to recompile your app for each language you want to support, leading to dozen of different apk's for the same program, 1 for each language. When you use string resources, you can make different value directories for different languages, so your app will support dozens of languages in 1 apk. Another plus is that for translation, you only have to send the xml, and the translator doesn't have to have knowledge of java.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby rmanromga » Tue Nov 25, 2008 3:20 pm

Thanks a lot... that makes a lot of sense...I'll keep this in mind and start using my Stirngs.xml file!!
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Postby Malefico » Tue Nov 25, 2008 4:11 pm

is always raccomanded to separate content and presentation.. not only for multilanguage support :wink:
Malefico
Developer
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 7 guests