で選択したアイテムに依存するコンテンツがspinner2
である必要があります。は、spinner1
で選択されているものとは関係なく、case0 : R.array.subMenuTrans
からコンテンツを取ります。スピナーのコンテンツは、別のスピナーの選択したアイテムにどのように依存することができますか?
package com.example.game1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class DialogMenu extends AppCompatActivity {
Spinner spinner1;
Spinner spinner2; **spinners**
Spinner spinner3;
ArrayAdapter<CharSequence> adapter1;
ArrayAdapter<CharSequence> adapter2;
ArrayAdapter<CharSequence> adapter3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog_menu);
spinner1 = (Spinner) findViewById(R.id.menu);
adapter1 = ArrayAdapter.createFromResource(this, R.array.menu, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override // TODO Auto-generated method stub
public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
Toast.makeText(getBaseContext(), spinner1.getSelectedItemPosition() + " is selected.", Toast.LENGTH_LONG).show();
}
@Override// TODO Auto-generated method stub
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
spinner2 = (Spinner) findViewById(R.id.submenu);
int options = spinner1.getSelectedItemPosition();
switch (options) {
case 0://spinner2 takes only content of case0,should take all cases depenting on selection of spinner1....
adapter2 = ArrayAdapter.createFromResource(this, R.array.subMenuTrans, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
case 1:
adapter2 = ArrayAdapter.createFromResource(this, R.array.subMenuSights, android.R.layout.simple_spinner_item);**takes content**
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
case 2:
adapter2 = ArrayAdapter.createFromResource(this, R.array.subMenuEdu, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
case 3:
adapter2 = ArrayAdapter.createFromResource(this, R.array.subMenuHeal, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
case 4:
adapter2 = ArrayAdapter.createFromResource(this, R.array.subMenuBus, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
case 5:
adapter2 = ArrayAdapter.createFromResource(this, R.array.subMenuAthl, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
case 6:
adapter2 = ArrayAdapter.createFromResource(this, R.array.subMenuPubServ, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}
spinner2.setAdapter(adapter2);
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override// TODO Auto-generated method stub
public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
Toast.makeText(getBaseContext(), spinner2.getSelectedItemPosition() + " is selected.", Toast.LENGTH_LONG).show();
}
@Override// TODO Auto-generated method stub
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
}