我是一名Android编程的初学者,最近遇到了一个问题。我正在制作一个简单的下拉列表应用程序。以下是代码。
package net.learn2develop.Basicviews6;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class BasicViews6Activity extends Activity {
String[] presidents;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
presidents =
getResources().getStringArray(R.array.presidents_array);
Spinner s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, presidents);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> arg0,
View arg1, int arg2, long arg3)
{
int index = arg0.getSelectedItemPosition();
Toast.makeText(getBaseContext(),
"You have selected item : " + presidents[index],
Toast.LENGTH_SHORT).show();
}
@Override
public Void onNothingdSelected(AdapterView<?> arg0) { }
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.basic_views6, menu);
return true;
}
}
但是它不允许我运行它,因为这些代码行:
s1.setOnItemSelectedListener(new OnItemSelectedListener()
public Void onNothingdSelected(AdapterView<?> arg0)
出现了以下错误:
类型 new AdapterView.OnItemSelectedListener(){} 必须实现继承的抽象方法 AdapterView.OnItemSelectedListener.onNothingSelected(AdapterView)
能否有人为我解释一下?非常感谢!