不抽象,并且不使用android中的recyclerView覆盖onCreateViewHolder的抽象方法

时间:2017-03-14 11:13:39

标签: android android-recyclerview recycler-adapter

我在Adapter中为Android Studio创建了Error:(20, 8) error: HR_Vacancy_Adapter is not abstract and does not override abstract method onCreateViewHolder(ViewGroup,int) in Adapter Error:(47, 31) error: onCreateViewHolder(ViewGroup,int) in HR_Vacancy_Adapter cannot override onCreateViewHolder(ViewGroup,int) in Adapter return type HR_Vacancy_Adapter is not compatible with HR_Vacancy_Adapter.MyViewHolder where VH is a type-variable: VH extends ViewHolder declared in class Adapter 扩展的类,但它显示以下错误。

Adapter

我的public class HR_Vacancy_Adapter extends RecyclerView.Adapter<HR_Vacancy_Adapter.MyViewHolder> { private List<HRVacancy> arr_hrvacancy; public class MyViewHolder extends RecyclerView.ViewHolder { public TextView tv_RAFno, tv_jobtitle, tv_postition, tv_Salary; public ImageView iv_companylogo; public MyViewHolder(View view) { super(view); tv_RAFno = (TextView) view.findViewById(R.id.tv_RAFno); tv_jobtitle = (TextView) view.findViewById(R.id.tv_jobtitle); tv_postition = (TextView) view.findViewById(R.id.tv_postition); tv_Salary = (TextView) view.findViewById(R.id.tv_Salary); iv_companylogo = (ImageView) view.findViewById(R.id.iv_companylogo); } } public HR_Vacancy_Adapter(List<HRVacancy> arr_hrvacancy) { this.arr_hrvacancy = arr_hrvacancy; } @Override public HR_Vacancy_Adapter onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_hr_vacancy, parent, false); return MyViewHolder(itemView); } @Override public void onBindViewHolder(MyViewHolder holder, int position) { super.onBindViewHolder(holder, position); HRVacancy hrvacancy = arr_hrvacancy.get(position); holder.tv_RAFno.setText(hrvacancy.getRafNo()); holder.tv_jobtitle.setText(hrvacancy.getPost()); holder.tv_postition.setText(hrvacancy.getPostition()); holder.tv_Salary.setText(hrvacancy.getSalary()); holder.iv_companylogo.setBackgroundResource(R.drawable.icon_app); } @Override public int getItemCount() { return arr_hrvacancy.size(); } }

{{1}}

3 个答案:

答案 0 :(得分:0)

您必须从onCreateViewHolder()返回HR_Vacancy_Adapter.MyViewHolder。

替换它:

@Override
public HR_Vacancy_Adapter onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_hr_vacancy, parent, false);
    return MyViewHolder(itemView);
}

有了这个:

@Override
public HR_Vacancy_Adapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_hr_vacancy, parent, false);
    return MyViewHolder(itemView);
}

答案 1 :(得分:0)

在您的dev中,您需要返回onCreateViewHolder()实施。

使用以下代码:

Viewholder

答案 2 :(得分:0)

由于错误 HR_Vacancy_Adapter与HR_Vacancy_Adapter.MyViewHolder 不兼容,因此仅返回您自己的视图持有者是不够的,但绑定持有者必须是您自己的类型。

 @Override
    public HR_Vacancy_Adapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_hr_vacancy, parent, false);
        return MyViewHolder(itemView);
}

@Override
public void onBindViewHolder(HR_Vacancy_Adapter.MyViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    HRVacancy hrvacancy = arr_hrvacancy.get(position);

    holder.tv_RAFno.setText(hrvacancy.getRafNo());
    holder.tv_jobtitle.setText(hrvacancy.getPost());
    holder.tv_postition.setText(hrvacancy.getPostition());
    holder.tv_Salary.setText(hrvacancy.getSalary());
    holder.iv_companylogo.setBackgroundResource(R.drawable.icon_app);
}