public class ExpAdapter : BaseExpandableListAdapter
{
private int seed = 1000;
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.GetSystemService(Context.LayoutInflaterService);
convertView = inflater.Inflate(Resource.Layout.inspection_row_2, null);
}
int currentID;
Random randomizer = new Random(seed);
TextView question = (TextView) convertView.FindViewById(Resource.Id.questionText);
RadioGroup radio = (RadioGroup) convertView.FindViewWithTag("actionGroup");
currentID = randomizer.Next(1,101);
radio.Id = currentID;
RadioButton pass = (RadioButton) convertView.FindViewWithTag("passed");
currentID = randomizer.Next(1,101);
pass.Id = currentID;
RadioButton fail = (RadioButton) convertView.FindViewWithTag("failed");
currentID = randomizer.Next(1,101);
fail.Id = currentID;
RadioButton correct = (RadioButton)convertView.FindViewWithTag("corrected");
currentID = randomizer.Next(1,101);
correct.Id = currentID;
RadioButton na = (RadioButton)convertView.FindViewWithTag("na");
currentID = randomizer.Next(1,101);
na.Id = currentID;
string[][] items = questions.childItems();
question.Text = items[groupPosition][childPosition];
seed++;
return convertView;
}
}
중단 점을 사용하여 위의 단계를 수행하려면 currentID = 1을 실행하는 것이 좋습니다. MonoDroid는 부모 그룹 아래에 자식 컨트롤 그룹을 만들고 currentID는 ALWAYS = 1이므로 위 메서드는 반복적으로 호출됩니다. 전체 클래스에서 private static 변수로 currentID 및 randomizer를 만들려고했습니다. 같은 결과.C# 임의로 항상 동일한 번호
편집 : GetChildView를 호출 할 때마다 시드 값이 다른 새 임의 인스턴스를 만들려고했습니다. 위 코드는 내가 어떻게했는지 보여주기 위해 편집되었습니다. 여전히 currentID의 값은 항상 1입니다. 아래는 Locals의 랜더 마이저에 대한 정보 스크린 샷입니다. 이 정보는 시드 번호와 관계없이 동일하게 보입니다. ???
랜덤 라이저에 씨앗을 먹이려고 했습니까? –
예. 같은 결과. 또한, 내 예제에서 시드를 사용하면 반복 할 때마다 동일한 숫자가 생성된다는 것을 이해합니다. 번호가 개체의 ID에 사용되고 있으며 고유해야합니다. – jmease
당신이 나에게 묻고있는 것을 이해하지 못합니다. DateTime을 사용하여 새로운 무작위 객체를 만든 다음 다음 임의의 숫자를 5 번 잡아서 GetChildView의 다음 반복 전에 5 월에 새로운 무작위 객체가 현재 DateTime을 기반으로 만들어지기를 기대합니다. – jmease