Android Spinner error: getOnItemSelectedListener in AdapterView cannot be applied

Android Spinner error: getOnItemSelectedListener in AdapterView cannot be applied

我正在使用一个简单的微调器在整数数组中显示买入值。 Gradle 构建中的错误显示:method getOnItemSelectedListener in class AdapterView<T> cannot be applied to given types。没有必需的参数,错误原因如下:actual and formal arguments lists differ in length where T is a type-variable: T extends Adapter declared in class AdapterView。我不确定如何解决出现在 (this):

上的错误
spinner.getOnItemSelectedListener(this);

我认为这是正确的做法,因为我告诉微调器 this activity 负责监听微调器上的事件。

这是我的代码:

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;


public class HomeActivity extends Activity implements AdapterView.OnItemSelectedListener{

    Spinner spinner;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Get the view from home_activity.xml
        setContentView(R.layout.home_activity);

        // initialize spinner
        spinner = (Spinner) findViewById(R.id.buyInSpinner);

        ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.buy_in, android.R.layout.simple_spinner_item);
        spinner.setAdapter(adapter);
        spinner.getOnItemSelectedListener(this);

    } // end onCreate method

    @Override
    public void onItemSelected(AdapterView<?> adapterView, View v, int i, long l)
    {
        TextView myText = (TextView) v;
        Toast.makeText(this, "You Selected "+myText.getText(), Toast.LENGTH_SHORT).show();
    } // end onItemSelected method

    @Override
    public void onNothingSelected(AdapterView<?> adapterView)
    {
        Toast.makeText(this, "You Must Buy-In To Play", Toast.LENGTH_SHORT).show();
    } // end onNothingSelected method

} // end HomeActivity class

为什么要get没有变量? 我认为在这种情况下你应该使用 spinner.setOnItemSelectedListener(this); 而不是