CZen Lau CZen Lau - 5 months ago 103
Android Question

Error with spinner.setOnItemClickListener() inside Fragment

I'm new to Android development, I having some problem which unable to resolve.
I tried to implement a Spinner inside Fragment, now it having problems with the spinner.setOnItemClickListener() method,

It showing an error message:

(android.widget.AdapterView.OnItemClickListener) in Spinner cannot be
applied to (anonymous

Here is my code:

public class CheckAvailabilityFragment extends Fragment {
Spinner spinner;
ArrayAdapter<CharSequence> adapter;

public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_check_availability, container,false);
spinner = (Spinner)getView().findViewById(;
adapter = ArrayAdapter.createFromResource(getActivity().getBaseContext(),R.array.venue,android.R.layout.simple_list_item_1);

spinner.setOnItemClickListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getBaseContext(), parent.getItemAtPosition(position) + " selected", Toast.LENGTH_SHORT).show();

public void onNothingSelected(AdapterView<?> parent) {

return rootView;


You must use the correct listener type and setter method combination. You need to either call setOnItemSelectedListener() or implement OnItemClickListener. You cannot mix and match listener types with the wrong setter method.