我想从微调器中获取所选项目的“ID”。
这是我的代码:
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)];
};
请帮助我!
答案 0 :(得分:1)
你不应该在字符串中提取任何值。您只需通过所选项目的位置来了解该值。
sterren2Lems.ItemSelected += Sterren2Lems_ItemSelected;
void Sterren2Lems_ItemSelected (object sender, AdapterView.ItemSelectedEventArgs e)
{
test.Text = sterren1Lems[e.Position];
}
答案 1 :(得分:0)
你的案例中的任何一种方法都没有用,我通过讨论得知你能从数组中获得一个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());
OR
$handle = fopen("mytext.txt", "r");
$content = fread($handle,filesize("mytext.txt"));
$noDigit = preg_match("/[0-9]/","",$content);
fclose($handle);