写android级联spinner时,报错。

写android级联时,报错。
Caused by: java.lang.RuntimeException: setOnItemClickListener cannot be used with a spinner.oid

代码如下:
sp_college.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override

        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            arrayAdapter=new ArrayAdapter<CharSequence>(MainActivity.this,android.R.layout.simple_spinner_item,college[i]);

            sp_college.setAdapter(arrayAdapter);

        }

    });


眼眸繁星
浏览 782回答 2
2回答

PIPIONE

用setOnItemSelectedListener可以吧

弑天下

spinnerView.setOnItemSelectedListener(&nbsp; &nbsp; new OnItemSelectedListener() {&nbsp; &nbsp; &nbsp; &nbsp; public void onItemSelected(AdapterView<?> parent,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; View view, int position, long id) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showToast("Spinner1: position="&nbsp; &nbsp;position&nbsp; &nbsp;" id="&nbsp; &nbsp;id);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; public void onNothingSelected(AdapterView<?> parent) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showToast("Spinner1: unselected");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; 希望对你有用
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android