After experience spinner problems at the time to add more than 4 Activity in my main App (Xamarin Android) I builded one very simple App with the minimum minimum in order to play with spinners.
This test App is like the following:
MainActivity has only one Button that transfers to Activity1. In MainActivity there's no code, only the button:
namespace App2
{
[Activity(Label = "@ hide /app_name", Theme = "@STYLE /AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
Button Btn_1 = FindViewById<Button>(Resource.Id.button1);
Btn_1.Click += delegate
{
StartActivity(typeof(Activity1));
};
}
}
}
Activity1 has only the code corresponding to the Spinner. Nothing else.
namespace App2
{
[Activity(Label = "Activity1")]
public class Activity1 : Activity
{
private static Spinner N_Filter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.layout1);
// Create your application here
N_Filter = (Spinner)FindViewById(Resource.Id.nfiltros);
//- Definición Spinner Número de Filtros
N_Filter.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(N_Filter_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.Num_1a24, Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
N_Filter.Adapter = adapter;
}
private void N_Filter_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
int Xi = e.Position;
Xi = Xi * 2;
}
}
}
All the rest of the Activity2...4 are only empty activities add automatically Like:
namespace App2
{
[Activity(Label = "Activity3")]
public class Activity3 : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
}
}
}
At the time of add Activity 4 is when the following errors occurs: In line:
var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.Num_1a24, Android.Resource.Layout.SimpleSpinnerItem);
Exception error: System.MemberAccessException: 'Cannot create an instance of Android.Widget.ArrayAdapter`1[T] because Type.ContainsGenericParameters is true.'
And IF I REMOVE Activity4 the App WORKS again WITH NO ISSUE. If I add it again it fails...
Note: Num_1a24 is one string-array on strings.xml.