android如何获取 ID 的 spinner 吗?

发布时间: 2016/8/28 17:34:20
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我想要:"ID"的所选物料从 spinner

这里是我的代码︰

var sterren1Lems = new String[]
         {
                "1 out of 5 stars", "2 out of 5 stars", "3 out of 5 stars", "4 out of 5 stars", "5 out of 5 stars"
         };

            sterren2Lems = FindViewById<Spinner>(Resource.Id.sterrenLems);
            sterren2Lems.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, sterren1Lems);

            TextView test = FindViewById<TextView>(Resource.Id.test);

            sterren2Lems.ItemSelected += delegate
            {
                test.Text = sterren1Lems[Convert.ToInt32(sterren2Lems.SelectedItemId)];
            };

请帮助我 !

解决方法 1:

要么你的情况的方法没有工作,我要知道通过讨论你是能够获取单个 string 从数组。所以,只是用简单的循环来得到 id

sting yourString ="2 out of 5 stars";
string id = "";

for (int i = 0; i < yourString.Length; i++)
{
    if (Char.IsDigit(yourString[i]))
        result += str[i];
    else
        break;
}

string id = new String(yourString.TakeWhile(Char.IsDigit).ToArray());
官方微信
官方QQ群
31647020