For an Android application we are building, we added some string values to our /resources/values/strings XML file. Mono for Android detects this and generates a strongly typed value in a designer class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class String | |
{ | |
// aapt resource value: 0x7f070001 | |
public const int ApplicationName = 2131165185; | |
// aapt resource value: 0x7f07000f | |
public const int DataLoadingError = 2131165199; | |
// aapt resource value: 0x7f07000e | |
public const int ImageLoadingError = 2131165198; | |
// aapt resource value: 0x7f07000d | |
public const int UnexpectedError = 2131165197; | |
private String() | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="ApplicationName">My Android App</string> | |
<string name="UnexpectedError">Unexpected Error</string> | |
<string name="ImageLoadingError">Failed to load image</string> | |
<string name="DataLoadingError">Failed to load data</string> | |
</resources> |
The only problem is that the generated value is an integer, not the string value itself. So how can we get access to the string resource?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string applicationName = Resources.GetString(Resource.String.ApplicationName); |