我在Android Studio中實現微調。我有下面的代碼。我收到錯誤MainActivity must either be declared abstract or implement abstract method onItemSelected(AdapterView<?>, View, int, long) in OnItemSelectedListener
。但正如你在下面看到的,我已經實施了onItemSelected(AdapterView<?>, View, int, long)
。類必須聲明爲抽象或實現onItemSelected在OnItemSelectedListener中的抽象方法
此外,當我運行的代碼,我看到錯誤MainActivity is not abstract and does not override abstract method onNothingSelected(AdapterView<?>) in OnItemSelectedListener
我缺少什麼?
public class MainActivity extends AppCompatActivity implements OnItemSelectedListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context context = getApplicationContext();
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner_supplychainEntities);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
R.array.spinner_options, android.R.layout.simple_spinner_item);
spinner.setOnItemSelectedListener(MainActivity.this);
spinner.setAdapter(adapter);
}
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//stuff here to handle item selection
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Log.i("GTOUTOUT", "Nothing Selected");
}
});
}