C# - Fill Spinner with an array from resource file

旧时模样 提交于 2019-12-11 17:04:26

问题


(I am struggling with a simple problem I think!?

In my android app I made a spinner that will be filled with 2 values: On and Off. So I created a file called Arrays.xml in Resources/values/

Now I thought that I need something like this, but this doesn't work:

Spinner ActionSpinner = FindViewById<Spinner>(Resource.Id.ActionSpinner);
ActionSpinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(ActionSpinner_ItemSelected);
var ActionSpinnerAdapter = ArrayAdapter.CreateFromResource(this, Resource.Array.action_array, Android.Resource.Layout.SimpleSpinnerItem);
ActionSpinnerAdapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem);
ActionSpinner.Adapter = ActionSpinnerAdapter;

The spinner stays empty and I don't know what to do... Someone else asked this question too on this site, but this awnser doesn't seem to work for me. This was his awnser:

ArrayAdapter<String> adp1=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1, list);

Any suggestions?

来源:https://stackoverflow.com/questions/53859338/c-sharp-fill-spinner-with-an-array-from-resource-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!