I'm' having a hard time trying to make my ArrayAdapter work - been using custom ArrayAdapter before with no problems, but this time I'm not sure what's going on.
I'm tryin to create ListView using adapter that will be showing two strings (mName, mLocation) of every WeekViewEvent object:
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
ArrayAdapter:
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;
}
}
but AndroidStudio highlights the part where I'm taking object position: WeekViewEvent wvevent = getItem(position);
as incompatible type (picture below):
I got stuck :/ Do you have any ideas what's wrong with my code? THANK YOU IN ADVANCE!
this should work
change Testowa
to -> WeekViewEvent
public TEventAdapter (Context context,ArrayList<Testowa
>testowyeventarray)
public class TEventAdapter extends ArrayAdapter<Testowa
>
public class TEventAdapter extends ArrayAdapter<WeekViewEvent> {
public TEventAdapter (Context context, ArrayList<WeekViewEvent> weekVieweEvent){
super(context, 0, weekVieweEvent);}
@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;
}
}