Spinner2 で Spinner1 の可視性を変更しようとしています。コードは正常にコンパイルされますが、開くとアプリがクラッシュします。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner)findViewById(R.id.spinner2);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onNothingSelected(AdapterView<?> arg0) {
}
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
Spinner spinner = (Spinner)findViewById(R.id.spinner2);
Spinner spinner1 = (Spinner)findViewById(R.id.spinner1);
TextView textview1 = (TextView)findViewById(R.id.textView1);
if (spinner.getSelectedItemPosition() == 1) {
textview1.setVisibility(View.VISIBLE);
spinner1.setVisibility(View.VISIBLE);
}
}
});
}