我尝试在Recyclerview中显示文字。 因此我将JsonData解析为ArrayList> 我得到这个内容后,我调用以下方法:
private void loadprevEvents() {
for (HashMap<String, String> data :datalist){
items_for_preview.addString(data.get("names"));
items_for_preview.addString("imageurl");
}
Customlist adapter = new Customlist_upcoming_events(items_for_preview,getApplicationContext());
}
不幸的是,这是我的问题,因为我尝试将数据保存在名为items_for_preview的列表中。 但我不能将字符串保存到此列表中。 我的应用说: 无法解析“getString” 这是我的Getter_Setter_Events_Prev类:
String date;
String imageUrl;
String name;
public Getter_Setter_Events_Prev(String date, String imageUrl, String name) {
this.date = date;
this.imageUrl = imageUrl;
this.name = name;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
这是我的适配器类:
public class Customlist_upcoming_events extends RecyclerView.Adapter<Customlist_upcoming_events.ViewHolder> {
private List<Getter_Setter_Events_Prev> items;
private Context context;
public Customlist_upcoming_events(List<Getter_Setter_Events_Prev> items, Context context) {
this.items = items;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.model_upcoming_events, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Getter_Setter_Events_Prev gt = items.get(position);
holder.name.setText(gt.getName());
}
@Override
public int getItemCount() {
return items.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public ImageView pic;
public ViewHolder(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.prev_events_name);
pic = (ImageView) itemView.findViewById(R.id.event_thumb);
}
}
}