gpt4 book ai didi

java - 无法将 getUrl() 传入 onBindViewHolder?

转载 作者:行者123 更新时间:2023-12-02 11:53:12 28 4
gpt4 key购买 nike

我有一个 ListSourceAdapter.java 类,

class ListSourceViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

ItemClickListener itemClickListener;
TextView source_title;
CircleImageView source_image;

public ListSourceViewHolder(View itemView) {
super(itemView);

source_title = (TextView) itemView.findViewById(R.id.source_name);
source_image = (CircleImageView) itemView.findViewById(R.id.source_image);
}

@Override
public void onClick(View v) {

itemClickListener.onClick(v, getAdapterPosition(), false);
}
}

public class ListSourceAdapter extends RecyclerView.Adapter<ListSourceViewHolder> {

private Context context;
private WebSite webSite;

public ListSourceAdapter(Context context, WebSite webSite) {
this.context = context;
this.webSite = webSite;
}

@Override
public ListSourceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View itemView = inflater.inflate(R.layout.source_layout, parent, false);

return new ListSourceViewHolder(itemView);
}

@Override
public void onBindViewHolder(ListSourceViewHolder holder, int position) {

StringBuilder iconBetterAPI = new StringBuilder("https://icons.better-idea.org/allicons.json?url=");
iconBetterAPI.append(webSite.getSources().get(position).getUrl());
}

@Override
public int getItemCount() {
return webSite.getSources().size();
}
}

onBindView中,我尝试使用getUrl(),但它说无法解析方法

我的WebSite.java模型类如下

public class WebSite {

private String status;
private List<Source> sources;

public WebSite() {
}

public WebSite(String status, List<Source> sources) {
this.status = status;
this.sources = sources;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public List<Source> getSources() {
return sources;
}

public void setSources(List<Source> sources) {
this.sources = sources;
}
}

Source.java 文件如下所示

class UrlsToLogs {

private String small, medium, large;

public String getSmall() {
return small;
}

public void setSmall(String small) {
this.small = small;
}

public String getMedium() {
return medium;
}

public void setMedium(String medium) {
this.medium = medium;
}

public String getLarge() {
return large;
}

public void setLarge(String large) {
this.large = large;
}
}

public class Source {

private String id, name, description, url, category, language, country;
private UrlsToLogs urlsToLogs;
private List<String> sortByAvailable;

public Source() {

}

public Source(String id, String name, String description, String url, String category, String language, String country, UrlsToLogs urlsToLogs, List<String> sortByAvailable) {
this.id = id;
this.name = name;
this.description = description;
this.url = url;
this.category = category;
this.language = language;
this.country = country;
this.urlsToLogs = urlsToLogs;
this.sortByAvailable = sortByAvailable;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public String getLanguage() {
return language;
}

public void setLanguage(String language) {
this.language = language;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public UrlsToLogs getUrlsToLogs() {
return urlsToLogs;
}

public void setUrlsToLogs(UrlsToLogs urlsToLogs) {
this.urlsToLogs = urlsToLogs;
}

public List<String> getSortByAvailable() {
return sortByAvailable;
}

public void setSortByAvailable(List<String> sortByAvailable) {
this.sortByAvailable = sortByAvailable;
}
}

IconBetterIdeaService 接口(interface)如下

public interface IconBetterIdeaService {

@GET
Call<IconBetterIdea> getIconUrl(@Url String url);

}

ItemClickListner 界面如下

public interface ItemClickListener {

void onClick(View view, int position, boolean isLongClick);
}

为什么我无法访问getUrl(),我的代码做错了什么?

enter image description here

最佳答案

尝试像这样创建单独的类

public class WebSite {

private String status;
private List<Source> sources;

public WebSite() {
}

public WebSite(String status, List<Source> sources) {
this.status = status;
this.sources = sources;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public List<Source> getSources() {
return sources;
}

public void setSources(List<Source> sources) {
this.sources = sources;
}
}

public class Source {

private String id, name, description, url, category, language, country;
private UrlsToLogs urlsToLogs;
private List<String> sortByAvailable;

public Source() {

}

public Source(String id, String name, String description, String url, String category, String language, String country, UrlsToLogs urlsToLogs, List<String> sortByAvailable) {
this.id = id;
this.name = name;
this.description = description;
this.url = url;
this.category = category;
this.language = language;
this.country = country;
this.urlsToLogs = urlsToLogs;
this.sortByAvailable = sortByAvailable;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public String getLanguage() {
return language;
}

public void setLanguage(String language) {
this.language = language;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public UrlsToLogs getUrlsToLogs() {
return urlsToLogs;
}

public void setUrlsToLogs(UrlsToLogs urlsToLogs) {
this.urlsToLogs = urlsToLogs;
}

public List<String> getSortByAvailable() {
return sortByAvailable;
}

public void setSortByAvailable(List<String> sortByAvailable) {
this.sortByAvailable = sortByAvailable;
}
}

public class UrlsToLogs {
private String small, medium, large;

public String getSmall() {
return small;
}

public void setSmall(String small) {
this.small = small;
}

public String getMedium() {
return medium;
}

public void setMedium(String medium) {
this.medium = medium;
}

public String getLarge() {
return large;
}

public void setLarge(String large) {
this.large = large;
}

}

输出

enter image description here

Clear-Rebuild and also check the imports

关于java - 无法将 getUrl() 传入 onBindViewHolder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47749514/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com