好吧,我对此还很陌生,但我已经明白了。我刚刚遇到了这个错误,我看到其他人也遇到了同样的问题,但标准修复(clean)对我不起作用。我不知道如何修复这些错误!请帮帮我!
第一个错误:
在我的else if语句中的sp2.setOnItemSelectedListener(new OnItemSelectedListener() {上,我一直收到这个错误:
类型AdapterView.OnItemSelectedListener.onNothingSelected(AdapterView) (){}必须实现继承的抽象方法AdapterView.OnItemSelectedListener
我在那里有onNothingSelected,它在我的if语句中工作,我的意思是我所做的一切就是复制、粘贴和编辑。
第二个错误:
在我的else if语句末尾的});上,我得到了错误:
语法错误,请插入";“以完成语句
但一切都在那里。语句已完成!
sp1.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelecteds(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
String reg_select = (sp1.getSelectedItem().toString());
if (reg_select.contentEquals("Southwest")){
sp2.setAdapter(sw_cit_adp);
sp2.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String sw_cit_select = (sp2.getSelectedItem().toString());
if (sw_cit_select.contentEquals("Lake Charles")){
sp3.setAdapter(sw_lake_charles_adp); }
else if (sw_cit_select.contentEquals("Iowa")){
sp3.setAdapter(sw_iowa_adp); }
;}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
};});}
else if (reg_select.contentEquals("South Central")){
sp2.setAdapter(sc_cit_adp);
sp2.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String sc_cit_select = (sp2.getSelectedItem().toString());
if (sc_cit_select.contentEquals("Lafayette")){
sp3.setAdapter(sc_lafayette_adp); }
else if (sc_cit_select.contentEquals("Gueydan")){
sp3.setAdapter(sc_gueydan_adp); }
;}
public void onNothingSelected(
AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
;
});
}发布于 2012-08-05 23:56:59
你在错误的地方使用了这个方法。你不能选择一个项目,然后选择任何东西,这是没有意义的。
您需要将方法放在侦听器下,就像onItemSelected一样,但不能放在onItemSelected内部。
这是它应该(基本上)看起来的样子:
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// Your code to do something with the selected item
}
});哦,你需要使用准确的方法名..。这是onItemSelected 而不是 onItemSelecteds
https://stackoverflow.com/questions/11817817
复制相似问题