写RecyclerView的adapter时报错,不知如何解决。
新手刚学用RecyclerView,在定义adapter类时就报错,错误见图。代码时参考书上的代码,并且也在网上搜索,看不出代码错在哪里?build通不过!
package com.example.recyclerviewapp; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.Adapter; import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import java.util.List; /** * Created by Lenovo on 2017/4/15. */ public class FruitAdapter extends RecyclerView.Adapter<FruitAdapter.myViewHolder>{ private List<Fruit> mFruitList; static class myViewHolder extends RecyclerView.ViewHolder{ ImageView fruitImage; TextView fruitName; public myViewHolder(View view) { super(view); fruitImage = (ImageView) view.findViewById(R.id.fruit_image); fruitName = (TextView) view.findViewById(R.id.fruit_name); } } public FruitAdapter(List<Fruit>fruitList){ mFruitList=fruitList; } @Override public myViewHolder OnCreateViewHolder(ViewGroup parent,int viewType){ View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fruit_item,parent,false); myViewHolder holder=new myViewHolder(view); return holder; } @Override public void onBindViewHolder(myViewHolder holder,int position){ Fruit fruit=mFruitList.get(position); holder.fruitImage.setImageResource(fruit.getImageId()); holder.fruitName.setText(fruit.getName()); } @Override public int getItemCount(){ return mFruitList.size(); } }
错误讯息已经很明显了。未重写onCreateViewHolder,大小写拼错了。(Android里方法名标准都是小写开头)
需要实现onCreateViewHolder方法
先把Java学好,就不会有这样的问题了版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。