我正在尝试创建一个回收站视图,以在instagram上的故事名称显示图片。 Java:36)在com.example.recyclerview.Adapter.onBindViewHolder(Adapter.java:14)
公共类适配器扩展了RecyclerView.Adapter {
List<Story> storiesList;
public Adapter(List<Story> itemsList) {
this.storiesList = itemsList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_main, parent, false);
return new ViewHolder(view) ;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
Story story = storiesList.get(position);
Log.d("street",story.getName());
viewHolder.name.setText(story.getName());
}
@Override
public int getItemCount() {
if (storiesList == null)return 0;
return storiesList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name;
ImageView sora;
public ViewHolder(@NonNull View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.nameofuser);
sora = itemView.findViewById(R.id.imageN);
}
}
}
LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_main, parent, false);
我想,当您应该在项目视图布局中添加类似R.layout.activity_main
的内容时,您正在尝试给R.layout.item_view
充气>尽管我可能看不对,因为我看不到您的
R.layout.activity_main
。希望有帮助。