Incompatible return type within customList

懵懂的女人 提交于 2019-12-11 22:37:08

问题


I've been having an issue. I've been trying to change the return type of getItem within my Custom List but this error keeps appearing: The return type is incompatible with ArrayAdapter.getItem(int). Can anyone help me?

Here's my Custom List's codes:

import java.io.File;
import java.net.URL;
import java.util.List;

import nyp.edu.sg.alumnigo.asynctask.GetEventsImageAsyncTask;


import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomList extends ArrayAdapter<String>{

    private final Activity context;
    private final List<Event> eventsList;

    public CustomList(Activity context, List<Event> eventsList) {
        super(context, R.layout.list_single);
        this.context = context;
        this.eventsList = eventsList;


    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if(eventsList.size() <= 0)
        {
            return 0;
        }
        return eventsList.size();
    }

    @Override
    public Event getItem(int position) {
        // TODO Auto-generated method stub
        return eventsList.get(position);
    }


    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {

        //set up the inflater...
        LayoutInflater inflater = context.getLayoutInflater();
        View rowView= inflater.inflate(R.layout.list_single, null, true);

        //reference the widgets...
        TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
        TextView txtDate = (TextView) rowView.findViewById(R.id.txt2);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
        Log.i("CustomList", "Start customList");

        txtTitle.setText(eventsList.get(position).getEvent_title());
        txtDate.setText(eventsList.get(position).getStart_date());
        new GetEventsImageAsyncTask(imageView).execute(Constants.HOST_NAME + "/"+ Constants.CMS_NAME+ "/" +eventsList.get(position).getSmall_picture_path());

        Log.i("CustomList", "End customList");

        return rowView;
    }
}

回答1:


look carefullly at your code..here..

public class CustomList extends ArrayAdapter<String>{}

that is your declaration for your customList ArrayAdatper and you are trying to return an Event type from your String ArrayAdapter.. do you get it now? so it's return type is goin to String.. do this rather

public class CustomList extends ArrayAdapter<Event>{



回答2:


Since you extends ArrayAdapter with String generic type

you can only return a String type



来源:https://stackoverflow.com/questions/26331445/incompatible-return-type-within-customlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!