Spinner Adapter from string array

tatmantatman USMember ✭✭

I got this code:

_scaleSpinner = FindViewById<Spinner> (Resource.Id.spinner);
var adapter = new ArrayAdapter<String> (this, Resource.Id.spinner, _scalesCollectionController.ScaleNames);
adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem);
_scaleSpinner.Adapter = adapter;

and I get this exception:

android.content.res.Resources$NotFoundException: Resource ID #0x7f060008 type #0x12 is not valid
[AndroidRuntime]    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)

Am I missing something in my project ? what is causing this exception?

Matt

Tagged:

Posts

  • tatmantatman USMember ✭✭

    Thnx Val. Changing the ArrayAdapter constructor to use Android.Resource.Layout.SimpleSpinnerItem fixed my problem.

    My question is why? I am little confused what that parameter is other than a resource id.

    Thnx
    Matt

  • CheesebaronCheesebaron DKInsider, University mod

    It is a resource id for what to display for each of the rows of the Spinner.

  • YoDesarrolloappYoDesarrolloapp MXMember ✭✭

    Hi Val Okafor I try to do something similar as you indicate but in my spinner doesn't show anything.
    This is my code.

    protected override void OnCreate(Bundle savedInstanceState)
    {
    base.OnCreate(savedInstanceState);
    SetContentView(Resource.Layout.LeeArchivoCSV);
    //My spinner
    Spinner sListaArchivos = FindViewById(Resource.Id.spinnerFileList);
    string[] archivoscsv = { };
    ObtenArchivosCSV acsv = new ObtenArchivosCSV();
    //This class is where we have the function for get the list of strings

            try
            {
                archivoscsv = acsv.CargaListaArchivos();
        //This function get the string[]
    
                ArrayAdapter adaptador = new ArrayAdapter<string>(this, Resource.Layout.LeeArchivoCSV, archivoscsv);
                adaptador.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                sListaArchivos.Adapter = adaptador;
            }
            catch(Exception e)
            {
                RunOnUiThread(() =>
                {
                    AlertDialog.Builder builder;
                    builder = new AlertDialog.Builder(this);
                    builder.SetTitle("Error");
                    builder.SetMessage("Error de ejecución:");
                    builder.SetCancelable(false);
                    builder.SetPositiveButton("OK", delegate { Console.WriteLine("Error:", e.Message); });
                    builder.Show();
                }
             );
            }
    

    }

    //This is the function CargaListaArchivos for for getting the string[]

    public string[] CargaListaArchivos()
    {
    string direccionArchivos = @//storage//self//primary;
    int i = 0;
    try
    {
    DirectoryInfo di = new DirectoryInfo(direccionArchivos);
    string[] archivos = { };
    //
    foreach (var fi in di.GetFiles("*.csv"))
    {
    archivos[i] = fi.Name; //Get the file name
    i++;
    }
    return archivos;
    }
    catch(Exception er)
    {
    string[] archivos = { };
    Console.WriteLine("Error de lectura", er.Message);
    return archivos;
    }
    }

    Could you please indicate me if I'm doing something wrong?
    Best regards.

Sign In or Register to comment.