我有以下api回复
"stories": [
{
"id": 754,
"title": "what ever bla bla bla",
- "feed": [
{
"feed_id": "2",
"title": "cnn",
"logo_url": "http://cnn.com/logo.gif",
"site_url": "http://cnn.com/"
}
]
}
代表这个我写了两个类:
public class StoryAbstract {
private long id;
private String title;
private List<Feeds> feed;
....
public List<Feeds> getFeeds() {
return feed;
}
public void setFeeds(List<Feeds> feeds) {
this.feed = feeds;
}
Feeds class:
public class Feeds {
private long feed_id;
private String title;
private String logo_url;
private String site_url;
public Feeds(long feed_id, String title, String logo_url, String site_url) {
this.feed_id = feed_id;
this.title = title;
this.logo_url = logo_url;
this.site_url = site_url;
}
public long getFeed_id() {
return feed_id;
}
public void setFeed_id(long feed_id) {
this.feed_id = feed_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLogo_url() {
return logo_url;
}
public void setLogo_url(String logo_url) {
this.logo_url = logo_url;
}
public String getSite_url() {
return site_url;
}
public void setSite_url(String site_url) {
this.site_url = site_url;
}
}
我试图在我的RecyclerView.ViewHolder中调用Feeds类的getTitle()方法,但我得到空值
private static class ViewHolderItem extends RecyclerView.ViewHolder implements View.OnClickListener {
private final TextView txtTitle;
...........
private StoryAbstract story;
private Feeds feeds;
private TextView feed_name;
....
public void bindStory(StoryAbstract story) {
this.story = story;
txtTitle.setText(story.getTitle());
......
feed_name.setText((CharSequence) feeds.getTitle());
我像这样调用bindStory:
viewHolderItem.bindStory(storyList.get(position - 1));
其中storyList
在故事适配器类中定义,如:
private List<StoryAbstract> storyList;