スピナーを使用して2つのレイアウトを切り替えようとしています.setContentViewを使用してそうしています. ただし、スピナーで選択すると、スピナーが「リッスン」を停止したように見えます。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_exercise);
getSupportActionBar().setHomeButtonEnabled(true);
initSpinnerType();}
public void initSpinnerType()
{
spinnerType = (Spinner) findViewById(R.id.spinner_type_of_training);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.trainingtype_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerType.setAdapter(adapter);
spinnerType = (Spinner) findViewById(R.id.spinner_type_of_training);
spinnerType.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(items[position].equals("Static"))
{
setContentView(R.layout.add_exercise_static);
spinnerType = (Spinner)findViewById(R.id.spinner_type_of_training);
spinnerType.setSelection(1,true);
System.out.println("static");
//button.setVisibility(View.VISIBLE);
}
else if(items[position].equals("Dynamic"))
{
setContentView(R.layout.add_exercise_static);
spinnerType = (Spinner)findViewById(R.id.spinner_type_of_training);
spinnerType.setSelection(2,true);
System.out.println("dynamic");
}
else
{
System.out.println("cardio");
//button.setVisibility(view.VISIBLE);
setContentView(R.layout.activity_add_exercise);
}
}