Spinner error on SetOnItemSelectedListener

2019-05-05 03:05发布

I have a spinner, and I do this

 public class Settings extends Activity {

String[] items = new String[] {"English", "Deutsch", "日語"};
 SharedPreferences prefs;
  SharedPreferences.Editor prefEditor;
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.settings);
        Spinner spinner = (Spinner) findViewById(R.id.spinner1);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, items);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
 spinner.setOnItemSelectedListener (new OnItemSelectedListener()  {


    });

There's syntax error suggesting OnItemSelectedListener cannot resolved into type. The method setOnItemSelectedListener is not applicable

2条回答
再贱就再见
2楼-- · 2019-05-05 03:27

Fix your imports. Press ctrl+shift+o if on Eclipse.

查看更多
小情绪 Triste *
3楼-- · 2019-05-05 03:38

This is common problem on eclipse. Just add it manually:

import android.widget.AdapterView.OnItemSelectedListener;
查看更多
登录 后发表回答