儀式の時点で、私が持っているのは 3 つのオプションを持つ 1 つのスピナーだけです。私がやりたいことは、オプション 1 が選択された場合、リスト 1 からランダムに選択され、オプション 2 がリスト 2 から選択されるなどです。スピナーを宣言して選択肢を入力するだけのコードが書かれていますが、ここからどこに行けばよいでしょうか? よろしくお願いします!
私のxmlのコードは次のとおりです。
<Spinner
android:id="@+id/alcohol"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:prompt="@string/prompt" />
次に、これは私の.javaファイルにあります:
setContentView(R.layout.activity_options);
// Set Alcohol Spinner
Spinner spinner = (Spinner) findViewById(R.id.alcohol);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.alcohol, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
みんなありがとう!