gpt4 book ai didi

android - RecyclerView 适配器给出错误 "The hierarchy of the type RecycleAdapter is inconsistent"

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:49:15 29 4
gpt4 key购买 nike

我正在尝试添加新的 RecyclerView到我的项目里面 Fragement .我正在关注 Link1 上的视频教程.当我尝试为 RecyclerView 创建适配器时,我开始收到此错误。我正在使用 Eclipse 朱诺。我无法弄清楚问题所在。请帮忙

我的代码:

public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.MyViewHolder> {

private LayoutInflater inflator;
List <Item> data = Collections.EMPTY_LIST;

public RecycleAdapter(Context context, List<Item> data){
inflator = LayoutInflater.from(context);
}

@Override
public int getItemCount() {
// TODO Auto-generated method stub
return data.size();
}


@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int arg1) {
View view = inflator.inflate(R.layout.row_staggered_new, parent, false);
MyViewHolder holder = MyViewHolder(view);
return holder;
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Item current = data.get(position);
holder.text.setText(current.title);
holder.image.setImageResource(current.image);

}

public static class MyViewHolder extends RecyclerView.ViewHolder{

public ImageView image;
public TextView text;

public MyViewHolder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.imageView1);
text = (TextView) itemView.findViewById(R.id.textview1);
}
}
}

两者都是 MyViewHolderRecycleAdapter正在给出错误 "The hierarchy of the type RecycleAdapter is inconsistent" .在 RecycleAdapter 的扩展部分,它显示错误 "Bound mismatch: The type RecycleAdapter.MyViewHolder is not a valid substitute for the bounded parameter <VH extends RecyclerView.ViewHolder> of the type RecyclerView.Adapter<VH>" .

有什么建议吗?

最佳答案

我发现了问题。问题是我使用的是旧版本和 v4 支持库,它不包含类 android.support.v4.view.ScrollingView 类。我用新版本替换了旧的 v4 库,错误消失了!

关于android - RecyclerView 适配器给出错误 "The hierarchy of the type RecycleAdapter is inconsistent",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29804910/

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