我試圖在我的項目中添加新的RecyclerView
Fragement
。我正在關注Link1的視頻教程。當我嘗試爲RecyclerView
創建適配器時,我開始出現此錯誤。我正在使用Eclipse Juno。我不知道這個問題。請幫助RecyclerView適配器給出錯誤「RecycleAdapter類型的層次結構不一致」
我的代碼:
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);
}
}
}
兩個MyViewHolder
和RecycleAdapter
是給錯誤"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>"
。
任何指針?
在'onCreateViewHolder'方法,不應該第二行是'MyViewHolder =新MyViewHolder(視圖)'?我想你錯過了'新' – NValchev