内customList不兼容的返回类型 [英] Incompatible return type within customList
问题描述
我一直有一个问题。我一直在想我的自定义列表中更改的getItem的返回类型,但这个错误一直出现:返回类型与ArrayAdapter.getItem(INT)不兼容。
谁能帮我?
下面是我的自定义列表的codeS:
进口的java.io.File;
进口的java.net.URL;
进口的java.util.List;进口nyp.edu.sg.alumnigo.asynctask.GetEventsImageAsyncTask;
进口android.app.Activity;
进口android.graphics.drawable.Drawable;
进口android.net.Uri;
进口android.util.Log;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.ArrayAdapter;
进口android.widget.ImageView;
进口android.widget.TextView;公共类CustomList扩展ArrayAdapter<串GT; { 私人最终活动范围内;
私人最终名单<事件> eventsList; 公共CustomList(Activity上下文,列表<事件> eventsList){
超(背景下,R.layout.list_single);
this.context =背景;
this.eventsList = eventsList;
} @覆盖
公众诠释的getCount(){
// TODO自动生成方法存根
如果(eventsList.size()&下; = 0)
{
返回0;
}
返回eventsList.size();
} @覆盖
公共事件的getItem(INT位置){
// TODO自动生成方法存根
返回eventsList.get(位置);
}
@覆盖
众长getItemId(INT位置){
// TODO自动生成方法存根
返回的位置;
} @覆盖
公共查看getView(INT位置,查看视图的ViewGroup父){ //设置充气...
LayoutInflater吹气= context.getLayoutInflater();
查看rowView = inflater.inflate(R.layout.list_single,空,真); //引用部件...
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,开始customList); txtTitle.setText(eventsList.get(位置).getEvent_title());
txtDate.setText(eventsList.get(位置).getStart_date());
新GetEventsImageAsyncTask(ImageView的).execute(Constants.HOST_NAME +/+ Constants.CMS_NAME +/+ eventsList.get(位置).getSmall_picture_path()); Log.i(CustomList,结束customList); 返回rowView;
}
}
carefullly看看你的code..here ..
公共类CustomList扩展ArrayAdapter<串GT; {}
这是你为你的customList ArrayAdatper申报和你试图返回
从字符串ArrayAdapter的事件类型..你得到它呢?所以它的返回类型布莱恩字符串..做到这一点,而
公共类CustomList扩展ArrayAdapter<事件> {
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;
}
}
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>{
这篇关于内customList不兼容的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!