在for循环中,我需要根据obj值创建一个项目:
例如:
for(int i=0;i<mylist.count;i++)
if(mylist[i].type==1)
{
//create radiobutton
}
else if(mylist[i].type==2)
{
//create ratingview
}
等等
如果在C#中创建了多个radiobutton,我如何区分radiobutton和ratingviews?就像我如何为每个项目创建标签或ID?
解:
如果找不到标签属性,只需创建一个:
public void test() {
for (int i = 0; i < 10; i++)
if (i<5)
{
//create radiobutton
radiobutton btn = new radiobutton
{
Text = "Click to Rotate Text!",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center,
tag = i
};
Console.WriteLine(btn.tag);
}
else if (i > 2)
{
//create ratingview
}
}
public class radiobutton : Button
{
public int tag;
}