0

I am currently working on an interactive book for Android in C# (right now I am doing a test version of it).

I store strings in the file Strings.xml (default file for strings).

In the Main.axml file I created a TextView:

<TextView
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/txttest1" />

This is just basic stuff to contain my strings where the story would be stored.

In the Strings.xml file is a test string:

<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>

So in this TextView txttest1 I want to load this string. In my MainActivity.cs file I did this:

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;
    }
}
}

How can I do this?

vortigon7
  • 11
  • 2
  • Refer this [Link](http://stackoverflow.com/questions/2183962/how-to-read-value-from-string-xml-in-android) – iSrinivasan27 Nov 25 '15 at 12:07
  • I don't know which Directive contains getResources but I cannot seem to find it. The name 'getResources' does not exist in the current context. – vortigon7 Nov 25 '15 at 12:37
  • Oh I found out that R.string.stringname can be found in Java, but I need this in C#....Or something like that, I'm kind of clueless about this. – vortigon7 Nov 25 '15 at 12:49

1 Answers1

0

I finally found the solution.

string customstring = GetString (Resource.String.storytest1);

This works. Without the GetString part it gives an error, but with the GetString and referring via Resource.String.stringname (if I get it correctly Resource.String refers to the Strings.xml in the Resources/values folder).

vortigon7
  • 11
  • 2