How to access a String programmatically

In some situations we have to access our String file from our Code.Every string file is stored in values > string.xml file.In layout design its easy to change but in code its easy to access too just use following command.

For instance we access out string.xml file with following ressources

 

<resources>
   
    <string name="yes">yes</string>
    <string name="no">no</string>
    <string name="Date">Date</string>
    <string name="Come">Come</string>
    <string name="Leave">Leave</string>
    <string name="Hours">hours</string>
    <string name="Backup">backup</string>
    <string name="Total_hours">TOTAL HOURS</string>
    <string name="Current_month">CURRENT MONTH</string>
    <string name="THIS_DAY">THIS DAY</string>
    <string name="Current_week">CURRENT WEEK</string>
    <string name="QTitle">SAVE</string>
    <string name="Query">Are you sure you want to save this file in </string>
    <string name="Directory">Directory?</string>
    <string name="Delete">Delete</string>
    <string name="Deletecsv">Delete CSV</string>
    <string name="savedirectory">Save CSV</string>
    <string name="restore">restore data?</string>
    <string name="dQuery">Do you want to delete all data?</string>
    <string name="dFROM">Please save data in csv format to storage!</string>
    <string name="Dateiname">Filename:</string>
    <string name="Permission">Permission is not granted</string>
    <string name="username">Date</string>
    <string name="OK">OK</string>
    <string name="CANCEL">CANCEL</string>
    <string name="EDIT">EDIT</string>
    <string name="SAVE">SAVE AS</string>
</resources>
String getString = getResources().getString(R.string.Date);

Leave a Reply

Your email address will not be published. Required fields are marked *