Skip to content

Trying to display arraylist in listview gets me this error unable to resolve contructor?

I imported an arraylist mEpisodeList from another class into my class to make a horizontal number scrollbar for available episodes , each number representing an episode I get this unable to resolve contructor error ,

here is the ArrayList mEpisodeList

here is the mehtod

import android.widget.ArrayAdapter;
import com.miz.loader.TvShowEpisodeLoader;
public class TvShowEpisodeDetailsFragment extends Fragment {
@Override
    public void onViewCreated(final View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // populate tvHisPosts layout
        mlistview = (ListView) view.findViewById(R.id.tvHisPosts);
        ArrayList<GridEpisode> episodelist = tvShowEpisodeLoader.getEpisodeList();
        // Create The Adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, episodelist);
        // Set The Adapter
        mlistview.setAdapter(adapter);

    }
}

Answer

Your ArrayAdapter is expecting a string array (ArrayAdapter<String>) and your actual ArrayList is of GridEpisode type, they do not match. Change this line;

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, episodelist);

to this:

ArrayAdapter<GridEpisode> adapter = new ArrayAdapter<>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, episodelist);

Notice the ArrayAdapter type is changed from String to GridEpisode.