Question

While using Dot42 it appears that I can access AddPreferencesFromResource(int) of PreferenceActivity class but the resource that gets passed to this method is not available to me. I expected the call to look like AddPreferencesFromResource(R.Xmls.Preferences), however R.Xmls does not exist. The xml folder contains preferences.xml and is stored next to layout, menu, etc. resource folders. However generated R.cs doesn't contain a class for Xmls. Included sample projects don't have any examples of usage of PreferenceActivity. Can anybody confirm whether or not preferences are supported in Dot42?

Was it helpful?

Solution

Your question is probably not so much how to populate a preference fragment from XML but more how to add an XML resource to a dot42 project and how to reference it.

You add an XML resource by adding an XML file to your Visual Studio (dot42) project as you would normally do; this is no different from adding an XML file to a non-dot42 project. Next, go to the properties of the file and set BuildAction to XmlResource.

enter image description here

Note that dot42 has no folder structure requirement (such as /res/xml/).

When you now compile again and type "R." you will see intellisence coming up with R.Xmls.

enter image description here

If you take a look at R.cs (under Properties), you will see it now includes R.Xmls with a generated member for your XML resource:

//------------------------------------------------------------------------------
// This file is automatically generated by dot42
//------------------------------------------------------------------------------

namespace PreferenceFragmentSample
{
    using System;

    public sealed class R
    {
        public sealed class Layouts
        {
            public const int MainLayout = 0x7f020000;
        }

        public sealed class Xmls
        {
            public const int preferences = 0x7f030000;
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top