【发布时间】:2015-11-25 12:02:24
【问题描述】:
我目前正在用 C# 编写一本用于 Android 的交互式书籍(现在我正在编写它的测试版本)。
我将 strings 存储在文件 Strings.xml (字符串的默认文件)中。
在 Main.axml 文件中,我创建了一个 TextView:
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txttest1" />
这只是包含存储故事的字符串的基本内容。
Strings.xml 文件中有一个测试字符串:
<string name="storytest1">This is where a piece of the story will go, bla bla, once
upon a time there was our Hero who did this and that...
</string>
所以在这个 TextView txttest1 我想加载这个字符串。 在我的 MainActivity.cs 文件中,我这样做了:
namespace InteractiveBookTest
{
[Activity (Label = "InteractiveBookTest", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
private TextView mTextView;
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
string customstring = "Here I should retrieve storytest1";
mTextView = FindViewById<TextView> (Resource.Id.txttest1);
mTextView.Text = customstring;
}
}
}
我该怎么做?
【问题讨论】:
-
参考这个Link
-
我不知道哪个指令包含 getResources 但我似乎找不到它。当前上下文中不存在名称“getResources”。
-
哦,我发现 R.string.stringname 可以在 Java 中找到,但我在 C# 中需要这个......或者类似的东西,我对此一无所知。跨度>