我想要:"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)];
};
请帮助我 !
要么你的情况的方法没有工作,我要知道通过讨论你是能够获取单个 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());