在我的 android 应用程序中,我想解决以下场景。
class Login extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutBuilder objLB=new LayoutBuilder(this);
objLB.createSpinner();
}
public void spinnerItemSelectedEvent(AdapterView<?> parent, View view,
int pos, long id)
{
}
}
class LayoutBuilder {
private Activity objActivity;
public LayoutBuilder(Activity a) {
objActivity = a;
}
public void createSpinner() {
final Spinner objSPItem = new Spinner(objActivity);
objSPItem.setOnItemSelectedListener(
new Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id)
{
// Do some common activity
objActivity.spinnerItemSelectedEvent(parent,view,pos,id);
// calling this for do some additional task
}
public void onNothingSelected(AdapterView<?> arg0) {}
});
objActivity.spinnerItemSelectedEvent()
}
}
问题是当我尝试从 createSpinner 方法中的“onItemSelected”列表器访问 spinnerItemSelectedEvent(parent,view,pos,id) 时,出现以下错误。
Activity 类型的方法 spinnerItemSelectedListener(AdapterView, View, int, long) 未定义
但是在侦听器之外,对该方法的访问可以正常工作(忽略参数列表)。这背后的原因是什么?是否存在解决此问题的替代方法?请帮助