1
내 스피너가 첫 번째 사례에 액세스하여 즉시 리디렉션 할 때 문제가 있습니다. 사용자가 선택하기 전에 :Android 스피너, 아무것도 선택하지 않았습니다.
@Override
public void onNothingSelected(AdapterView<?> view); {
// TODO Auto-generated method stub
}
메서드를 올바르게 사용하려면 어떻게해야합니까? 아래는 제 코드입니다.
// Creating adapter for spinner & choosing Drop down layout style - list view
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.event,android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(adapter);
//spinner needs to know who is responsible for handling events
spinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long l) {
//casting the view to textView
TextView myText=(TextView) view;
// use .getText to display what text was selected by user
Toast.makeText(this,"You Selected "+myText.getText(),Toast.LENGTH_SHORT).show();
switch (pos) {
case (0):
//Case selection redirecting user to 'Training Table'
Intent a = new Intent(Calendar.this, TrainingTable.class);
Calendar.this.startActivity(a);
break;
case (1):
//Case selection redirecting user to 'Race Table'
Intent b = new Intent(Calendar.this, Races.class);
Calendar.this.startActivity(b);
break;
case (2):
//Case selection redirecting user to 'Workshops page'
Intent c = new Intent(Calendar.this, Workshops.class);
Calendar.this.startActivity(c);
break;
}