这是模型类
public class Video {
private String videoTitle;
private String videoThumb;
private String videoChannel;
private String videoID;
// Constructor to convert JSON object into a Java class instance
public Video(JSONObject object) {
try {
JSONObject obj = object.getJSONObject("snippet");
this.videoTitle = obj.getString("title");
JSONObject obj3 = obj.getJSONObject("thumbnails").getJSONObject("maxres");
this.videoThumb = obj3.getString("url");
this.videoChannel = obj.getString("channelTitle");
//This is the Variable Which is not getting passed in other fragment
this.videoID = "eHarS-r_CC4";
} catch (JSONException e) {
e.printStackTrace();
}
}
public String getVideoTitle() { return videoTitle; }
public String getVideoThumb() {
return videoThumb;
}
public String getVideoChannel() {return videoChannel; }
public String getVideoID() {return videoID; }
}
这是适配器类:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolderVideo holder;
if (view == null) {
LayoutInflater inflater = LayoutInflater.from(context);
view = inflater.inflate(resource, parent, false);
Log.d("videoTitle", video.getVideoTitle());
final String videoID = video.getVideoID();
Log.d("videoID", videoID);
}
不是当我在 HomeFragment 中使用 Model 类和 Adapter 时,它为所有列表项同时传递 videoTitle 和 videoID,但是当我在其他片段中使用相同的模型类和 Adapter 时,它传递了 videoTitle,但会为 videoID 抛出以下错误。
慕码人2483693
郎朗坤
相关分类