我很难让我的 ArrayAdapter 工作 - 以前使用自定义 ArrayAdapter 没有问题,但这次我不确定发生了什么。
我正在尝试使用适配器创建 ListView,该适配器将显示每个 WeekViewEvent 对象的两个字符串(mName,mLocation):
public class WeekViewEvent implements Serializable{
private long mId;
private Calendar mStartTime;
private Calendar mEndTime;
private String mName;
private String mLocation;
private int mColor;
private boolean mAllDay;
private Shader mShader;
//construcotrs, setters, getters
阵列适配器:
public class TEventAdapter extends ArrayAdapter<Testowa> {
public TEventAdapter (Context context, ArrayList<Testowa> testowyeventarray){
super(context, 0, testowyeventarray);}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View pojedynczyItemView = convertView;
if(pojedynczyItemView==null){
pojedynczyItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
}
WeekViewEvent wvevent = getItem(position);
TextView tv1 = (TextView) pojedynczyItemView.findViewById(R.id.tv_lv1);
tv1.setText(wvevent.getName());
TextView tv2 = (TextView) pojedynczyItemView.findViewById(R.id.tv_lv2);
tv2.setText(wvevent.getLocation());
return pojedynczyItemView;
}
}
但 AndroidStudio 突出显示了我正在获取对象位置的部分:WeekViewEvent wvevent = getItem(position);
作为不兼容的类型(下图):
我被卡住了:/你有什么想法我的代码有什么问题吗?先感谢您!