Forum Xamarin.Forms

How to reference the resource files in android PCL project

I can't figure out how to reference android's resource files in the PCL project

       public class Alert : IAlert
        {
            private readonly Context _context;

            public Alert()
            {
                _context = Forms.Context;
            }

            public void ShowAlert(string title, string msg, Action<string> onSelect)
            {
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(_context);
                //How to reference resource file?
                alertBuilder.SetItems(_context.Resources.GetStringArray(_context.Resource), ((innersender, innerargs) =>
                {
                    onSelect(items[innerargs.Which]);
                }));
                AlertDialog dialog = alertBuilder.Create();
                dialog.SetCanceledOnTouchOutside(false);
                dialog.SetTitle(title);
                dialog.SetMessage(msg);
                dialog.Show();
            }
        }

Here is the Arrays.xml
<string-array name="test"><item>Is this question one?</item></string-array>

thanks

Answers

  • FinalChocoboFinalChocobo USMember ✭✭

    Nevermind i manage to figure out, something like
    string[] ids = _context.Resources.GetStringArray(Android.alpha.Resource.Array.test);
    alertBuilder.SetItems(ids, ((innersender, innerargs) =>
    {
    onSelect(ids[innerargs.Which]);
    }));

    however I encountered another problem, the alert doesn't show the options from the array, any idea?

Sign In or Register to comment.