Albert Albert - 1 year ago 131
Java Question

Error for fragment incompatible types: List cannot be converted to OnItemClickListener

I am new to android, I am try to build an app that listview to webview.
And i have couple issues.
First one is in my fragment, this fragment is for listview

Error:(32, 37) error: incompatible types: List cannot be converted to OnItemClickListener

And here is my code
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.view.ViewGroup;
import java.util.ArrayList;

public class List extends Fragment {
ListView list;
String [] Winners = {"A", "B", "C", "D", "E"};
OnSiteSelectedListener SiteListener;

public void onCreate(Bundle savedInstanceState)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_list, container,false);
list = (ListView) v.findViewById(;
list.setAdapter(new ArrayAdapter<String>(getActivity().getApplicationContext(),android.R.layout.simple_list_item_1,Winners));
return v;

public void onItemClick(AdapterView adapterView, View view, int position, long l)
public interface OnSiteSelectedListener {
public void onSiteSelected(int i);

public void setRefrence(OnSiteSelectedListener siteListener)
this.SiteListener = siteListener;


And How can I fix this issue

Answer Source

The List class needs to implement OnItemClickListener. You've already implemented the onItemClick() method, so you just need to add the interface to the class declaration:

public class List extends Fragment implements AdapterView.OnItemClickListener {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download