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#常に常に同じ番号
EDIT:GetChildViewへの呼び出しごとに異なるシード値を持つ新しいRandomインスタンスを作成しようとしました。上記のコードは、私がどのようにそれを行ったかを示すために編集されています。それでもcurrentIDの値は常に= 1です。以下は、Localsのランダマイザの情報のスクリーンショットです。この情報は、シード番号が何であるかにかかわらず同じように見えます。 ???
ランダム化装置に種子を供給しようとしましたか? –
はい。同じ結果。また、私の例でシードを使用すると、各繰り返しで同じ数値が生成されることは私の理解です。この番号はオブジェクトのIDに使用されており、一意である必要があります。 – jmease
私はあなたに何を聞いているのか分かりません。 DateTimeを使用して新しいRandomオブジェクトを作成し、次に現在のDateTimeに基づいて新しいRandomオブジェクトを作成するGetChildViewの次の反復の前に次の乱数を5回取得します。 – jmease