私はアンドロイドの新機能です。以下のコードでは、エンド・ユーザーが見たいセクションを選択し、リスト・ビューを表示します。私はスピナーをアクティブにすることはできません、私は別のセクションを選択していますが、それは1つだけのリストビューを示しています。アンドロイドスピナーをアクティブにするにはどうすればいいですか?
public class TeacherClasses extends AppCompatActivity implements AdapterView.OnItemClickListener,View.OnClickListener{
public String[] Section1 = {"Bonilla, Abbie", "Hernando, Roland Joseph", "Ko, Kritofer", "Manaig, Kathleen",
"Olalia, Jerome","Rosario, Kyle", "Sevilla, Karen", "Tancioco, Eron", "Villena, Mark" };
public String[] Section2 = {"Chavez, Stephanie", "Espana, Bren Alfred", "Faro, Ede", "Gonzales, Venice",
"Magora, Joshua James","Roman, Jairah", "Ramirez, Stephanie", "Tiboli, Jamalul", "Torrazo, Nicole" };
public String[] Section3 = {"Arbonida, Caye Anne", "De Guzman, Patricia", "Escandor, Jennifer", "Marzan, Rann",
"Menorca, Paula","Payofelin, Marlo", "Pimentel, Iris Coleen", "Queen, Elizabeth", "Unggoy, Monkey" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_teacher_classes);
Button btn_Sections = (Button) findViewById(R.id.btn_Sections);
btn_Sections.setOnClickListener(this);
CreateList();
}
private void CreateList() {
Spinner spn_Sections = (Spinner) findViewById(R.id.spn_Sections);
List<String> Sections = new ArrayList<String>();
Sections.add("Section 1");
Sections.add("Section 2");
Sections.add("Section 3");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,Sections);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spn_Sections.setAdapter(dataAdapter);
ListAdapter ClassAdapter = null;
String s = spn_Sections.getSelectedItem().toString();
if (s.equals("Section 1")) {
ClassAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Section1);
Toast.makeText(this, "Section 1", Toast.LENGTH_SHORT).show();
} else if (s.equals("Section 2")) {
ClassAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Section2);
Toast.makeText(this, "Section 2", Toast.LENGTH_SHORT).show();
} else if (s.equals("Section 3")) {
ClassAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Section3);
Toast.makeText(this, "Section 3", Toast.LENGTH_SHORT).show();
}
ListView MyClasses = (ListView)findViewById(R.id.list_ClassList);
MyClasses.setAdapter(ClassAdapter);
MyClasses.setOnItemClickListener(this);
}
あなたのコードのJava規則に従ってください。 –
spinnerItemClickListenerにアダプタを設定 –