添加對象的名單在我的主要活動,我有兩個列表:不能到我的收藏
private List<Feed> feedItems;
private ArrayList<Object> adItems() {
ArrayList<Object> adItems = new ArrayList<>();
adItems.add("image");
adItems.add("image");
adItems.add("image");
return adItems;
}
第一個列表代表我feedItems,這是從我的網絡模型中得到的。第二個列表只是一個靜態圖像列表。我正在嘗試設置原生廣告,但我只是後退一步,只是提供圖像的Feed以證明覆蓋我的RecyclerAdapter以生成多個視圖。
feedRecyclerAdapter = new FeedRecyclerAdapter(this, feedItems, new ImageLoader(new FeedItemFileCache(this)), adItems());
在這裏,我通過我的adItems()在我的FeedRecyclerAdapter作爲最後paramater對象列表,並在適配器類本身我把它在構造函數中:
public FeedRecyclerAdapter(Context context, List<Feed> feedItems, ImageLoader feedItemImageLoader, List<Object> adItems) {
this.context = context;
this.feedItems = feedItems;
this.feedItemImageLoader = feedItemImageLoader;
feedItems.addAll(adItems);
}
最後一行feedItems.addAll(adItems);
在這裏我得到了以下錯誤消息:
Error:(43, 18) error: no suitable method found for addAll(List<Object>)
method Collection.addAll(Collection<? extends Feed>) is not applicable
(argument mismatch; List<Object> cannot be converted to Collection<? extends Feed>)
method List.addAll(Collection<? extends Feed>) is not applicable
(argument mismatch; List<Object> cannot be converted to Collection<? extends Feed>)
我的飼料對象是這樣的:
public class Feed {
public static final String CLASS_NAME = "Feed";
public static final String MARKET_CLASS_NAME = "MarketFeed";
private String objectId;
private String createdAt;
/**
* Can be a ParsePointer but we are using a relational include query to get the whole object
*/
private Design designId;
// Not part of the model, calculated at run time.
private String timestampText;
private boolean isInPersonalGallery;
private boolean isLiked;
private List<Comment> comments;
// Related to Market Feed Items
private DisplayedSide displayedSide = DisplayedSide.FRONT;
public enum DisplayedSide {
FRONT,
BACK
}
public String getObjectId() {
return objectId;
}
public Design getDesign() {
return designId;
}
public Date getCreatedAt() {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
Date date = null;
try {
date = dateFormat.parse(createdAt);
} catch (ParseException e) {
e.printStackTrace();
Log.d("Feed", "Couldn't parse createdAt date when requested " + createdAt);
}
return date;
}
public String getTimestampText() {
return timestampText;
}
public void setTimestampText(String timestampText) {
this.timestampText = timestampText;
}
public boolean isInPersonalGallery() {
return isInPersonalGallery;
}
public void setInPersonalGallery(boolean inPersonalGallery) {
isInPersonalGallery = inPersonalGallery;
}
public boolean isLiked() {
return isLiked;
}
public void setLiked(boolean liked) {
isLiked = liked;
}
public List<Comment> getComments() {
return comments;
}
public void setComments(List<Comment> comments) {
this.comments = comments;
}
public DisplayedSide getDisplayedSide() {
return displayedSide;
}
public void setDisplayedSide(DisplayedSide displayedSide) {
this.displayedSide = displayedSide;
}
}
總之,我試圖在我的Collection中的主對象feedItems之間撒上一些圖像或adItems。爲什麼我不能簡單地將它們附加到我的主要列表中?我能做些什麼呢?
'列表'只能保存'Feed'對象。如果你想要它,它必須是'List
@bluemunch你的類型不匹配 – Nisarg
你的錯誤本身描述的問題:**參數不匹配;列表