我正在尝试让我的 Spinner1 更改 spinner2 上的可见性。我的代码编译正常,但应用程序在打开时崩溃。
@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);
}
}
});
}