使用此代码时,出现以下错误:
构造函数ArrayAdapter(new AdapterView.OnItemSelectedListener(){},int,String [])未定义
谁能帮助纠正这一点?谢谢
private void setDynamicSpinnerBE() { beSpinner = (Spinner) findViewById(R.id.spBE); final String[] itemsSpinner2; lensSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Integer focalLength = (Integer) parent.getAdapter().getItem( position); itemsSpinner2 = getBellowsExtension(focalLength, maxBellows, precision); ArrayAdapter<CharSequence> beAdapter = new ArrayAdapter<CharSequence>( this, android.R.layout.simple_spinner_item, itemsSpinner2); beAdapter .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); beSpinner.setAdapter(beAdapter); } public void onNothingSelected(AdapterView<?> parent) { beSpinner.setAdapter(null); } } ); ... }
在构造函数中将您的新代码添加ArrayAdapter到以下行:
ArrayAdapter
ArrayAdapter<CharSequence> beAdapter = new ArrayAdapter<CharSequence>(this,
this指向OnItemSelectedListener您所在类的当前实例而不是父视图,这是发生问题的原因,因为ArrayAdapter它没有匹配的构造函数。您应该尝试使用MyParentView.this(您所在MyParentView的视图的名称在哪里)代替传递适当的实例。
this
OnItemSelectedListener
MyParentView.this
MyParentView