Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 方法不覆盖自定义Recyclerview适配器中的超类的方法_Java_Android_Android Recyclerview - Fatal编程技术网

Java 方法不覆盖自定义Recyclerview适配器中的超类的方法

Java 方法不覆盖自定义Recyclerview适配器中的超类的方法,java,android,android-recyclerview,Java,Android,Android Recyclerview,我有一个自定义类WORecyclerListAdapter,它扩展了RecyclerView.Adapter 我还有另一个自定义类ZWORecyclerListAdapter,它扩展了WORecyclerListAdapter public class ZWORecyclerListAdapter extends WORecyclerListAdapter{ public ZWORecyclerListAdapter(){ super(); } p

我有一个自定义类
WORecyclerListAdapter
,它扩展了
RecyclerView.Adapter

我还有另一个自定义类
ZWORecyclerListAdapter
,它扩展了
WORecyclerListAdapter

public class ZWORecyclerListAdapter extends WORecyclerListAdapter{


    public ZWORecyclerListAdapter(){
        super();

    }

    public ZWORecyclerListAdapter(ArrayList<WorkOrder> items, int selectedWOPos, boolean mTwoPane) {
        super();
        try{ workorders = items;
            this.currentSelectedWOPos = selectedWOPos;
            this.mTwoPane = mTwoPane;
        }catch(Exception e)
        { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error, e.getMessage());}
    }

    @Override
    public WORecyclerListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        try{ view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.z_workorder_list_content, parent, false);
        }catch(Exception e)
        { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error, e.getMessage());}
        //return new ViewHolder(view);
        return new WORecyclerListAdapter.ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        try { holder.mItem = workorders.get(position);
            holder.mView.setSelected(position == currentSelectedWOPos && mTwoPane);
            if(position== currentSelectedWOPos && mTwoPane) {
                currentSelectedView = holder.mView;
            }
            holder.mIdView.setText(workorders.get(position).getDisplayableWorkOrderNum());
            holder.mContentView.setText(workorders.get(position).getShortText());
            holder.statusIcon.setImageResource(holder.mItem.getMobileObjStatusDrawable());
            //holder.woTypeIcon.setImageResource(holder.mItem.getWOTypeDrawable());

            //-------------------------------------------------------------
            holder.locationTxt.setText(workorders.get(0).getFuncLocation());
            holder.typeTxt.setText(workorders.get(0).getOrderType());
            //-------------------------------------------------------------

            holder.priorityIcon.setImageResource(holder.mItem.getPriorityDrawable());
            if(holder.mItem.getBasicFnshDate() != null)
                holder.dueDateTxt.setText(Common.getFormattedDate(holder.mItem.getBasicFnshDate().getTime()));
            if(!holder.mItem.isAttachmentAvailable())
                holder.attachmentIcon.setVisibility(View.INVISIBLE);
            else
                holder.attachmentIcon.setVisibility(View.VISIBLE);
            if(holder.mItem.isErrorEntity()){
                holder.errorIndicator.setVisibility(View.VISIBLE);
            }else {
                holder.errorIndicator.setVisibility(View.GONE);
            }
            holder.mView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int clickPos = holder.getAdapterPosition();
                    if (clickPos != currentSelectedWOPos && mTwoPane) {
                        currentSelectedWOPos = clickPos;
                        if (currentSelectedView != null)
                            currentSelectedView.setSelected(false);
                        currentSelectedView = v;
                        v.setSelected(true);
                        onSelectWOListItem(clickPos);
                    }
                    if(!mTwoPane)
                        onSelectWOListItem(clickPos);
                }
            });
        }catch(Exception e)
        { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error,e.getMessage());}
    }

    @Override
    public void onSelectWOListItem(int position) {

    }




    public class ViewHolder extends RecyclerView.ViewHolder {
        public final View mView;
        public final View errorIndicator;
        public final TextView mIdView;
        public final TextView mContentView;
        public final ImageView statusIcon;
        public final ImageView priorityIcon;
        //public final ImageView woTypeIcon;
        public final ImageView attachmentIcon;
        public final TextView dueDateTxt;
        public WorkOrder mItem;

        public final TextView locationTxt;
        public final TextView typeTxt;

        public ViewHolder(View view) {
            super(view);
            mView = view;
            mIdView = (TextView) view.findViewById(R.id.id);
            mContentView = (TextView) view.findViewById(R.id.short_text);
            statusIcon = (ImageView) view.findViewById(R.id.status_icon);
            priorityIcon = (ImageView) view.findViewById(R.id.wo_priority_icon);
            //woTypeIcon = (ImageView) view.findViewById(R.id.type_icon);
            locationTxt = (TextView) view.findViewById(R.id.locationTxt);
            attachmentIcon = (ImageView) view.findViewById(R.id.attach_icon);
            dueDateTxt = (TextView) view.findViewById(R.id.dueDateTxt);
            errorIndicator = view.findViewById(R.id.errorIndicator);

            typeTxt = (TextView) view.findViewById(R.id.type_txt);
        }

        @Override
        public String toString() {
            try{
                return super.toString() + " '" + mContentView.getText() + "'";
            }catch(Exception e)
            { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error,e.getMessage());}
            return "";
        }
    }


}


When I override "onBindViewHolder" method in ZWORecyclerListAdapter class it showing as "method doesnot override method of super class"

This "onBindViewHolder" method is already there in "WORecyclerListAdapter" class.
ZWORecyclerListAdapter
扩展了
WORecyclerListAdapter

它们都有
WORecyclerListAdapter
ZWORecyclerListAdapter
具有不同的布局

下面是WORecyclerListAdapter类:

public abstract class WORecyclerListAdapter extends RecyclerView.Adapter<WORecyclerListAdapter.ViewHolder> {

    protected ArrayList<WorkOrder> workorders;
    protected int currentSelectedWOPos;
    protected View currentSelectedView;
    protected boolean mTwoPane;

    public WORecyclerListAdapter(){

    }

    public WORecyclerListAdapter(ArrayList<WorkOrder> items, int selectedWOPos, boolean mTwoPane) {
       try{ workorders = items;
        this.currentSelectedWOPos = selectedWOPos;
           this.mTwoPane = mTwoPane;
       }catch(Exception e)
       { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error, e.getMessage());}
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        try{ view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.workorder_list_content, parent, false);
        }catch(Exception e)
        { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error,e.getMessage());}
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        try { holder.mItem = workorders.get(position);
        holder.mView.setSelected(position == currentSelectedWOPos && mTwoPane);
        if(position== currentSelectedWOPos && mTwoPane) {
            currentSelectedView = holder.mView;
        }
        holder.mIdView.setText(workorders.get(position).getDisplayableWorkOrderNum());
        holder.mContentView.setText(workorders.get(position).getShortText());
        holder.statusIcon.setImageResource(holder.mItem.getMobileObjStatusDrawable());
            holder.woTypeIcon.setImageResource(holder.mItem.getWOTypeDrawable());
        holder.priorityIcon.setImageResource(holder.mItem.getPriorityDrawable());
            if(holder.mItem.getBasicFnshDate() != null)
                holder.dueDateTxt.setText(Common.getFormattedDate(holder.mItem.getBasicFnshDate().getTime()));
            if(!holder.mItem.isAttachmentAvailable())
                holder.attachmentIcon.setVisibility(View.INVISIBLE);
            else
                holder.attachmentIcon.setVisibility(View.VISIBLE);
            if(holder.mItem.isErrorEntity()){
                holder.errorIndicator.setVisibility(View.VISIBLE);
            }else {
                holder.errorIndicator.setVisibility(View.GONE);
            }
        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int clickPos = holder.getAdapterPosition();
                if (clickPos != currentSelectedWOPos && mTwoPane) {
                    currentSelectedWOPos = clickPos;
                        if (currentSelectedView != null)
                            currentSelectedView.setSelected(false);
                        currentSelectedView = v;
                        v.setSelected(true);
                    onSelectWOListItem(clickPos);
                }
                if(!mTwoPane)
                    onSelectWOListItem(clickPos);

            }
        });
        }catch(Exception e)
        { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error,e.getMessage());}
    }

    public abstract void onSelectWOListItem(int position);

    public void onUnSelectWOListItem(int position){}

    @Override
    public int getItemCount() {
       try{ return workorders.size();
       }catch(Exception e)
       { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error,e.getMessage());}
    return 0;}

    public class ViewHolder extends RecyclerView.ViewHolder {
        public final View mView;
        public final View errorIndicator;
        public final TextView mIdView;
        public final TextView mContentView;
        public final ImageView statusIcon;
        public final ImageView priorityIcon;
        public final ImageView woTypeIcon;
        public final ImageView attachmentIcon;
        public final TextView dueDateTxt;
        public WorkOrder mItem;

        public ViewHolder(View view) {
            super(view);
            mView = view;
            mIdView = (TextView) view.findViewById(R.id.id);
            mContentView = (TextView) view.findViewById(R.id.short_text);
            statusIcon = (ImageView) view.findViewById(R.id.status_icon);
            priorityIcon = (ImageView) view.findViewById(R.id.wo_priority_icon);
            woTypeIcon = (ImageView) view.findViewById(R.id.type_icon);
            attachmentIcon = (ImageView) view.findViewById(R.id.attach_icon);
            dueDateTxt = (TextView) view.findViewById(R.id.dueDateTxt);
            errorIndicator = view.findViewById(R.id.errorIndicator);
        }

        @Override
        public String toString() {
            try{
            return super.toString() + " '" + mContentView.getText() + "'";
            }catch(Exception e)
            { DliteLogger.WriteLog(this.getClass(), AppSettings.LogLevel.Error,e.getMessage());}
        return "";
        }
    }

}
如何覆盖
ZWORecyclerListAdapter
中的
onBindViewHolder
方法

我试过了,但没有成功。
请在这方面帮助我。提前谢谢。

由于您的
ZWORecyclerListAdapter
扩展了
WORecyclerListAdapter
它扩展了
RecyclerView.Adapter
,因此您的
onBindViewHolder
方法的第二个参数必须是
WORecyclerListAdapter.ViewHolder
。您使用的是
ZWORecyclerListAdapter
自己的
ViewHolder
,它不起作用


您可能需要创建一个通用的
视图夹
,它将适用于两个适配器。

添加有问题的类。您的代码有一些问题。这是显而易见的,但您要求我们修复您的代码,而不显示您的代码。@ADM,已添加类。请检查更新后的帖子。@VladyslavMatviienko,你检查更新后的帖子了吗?@Naveen没有,因为它没有通知我你的更新,所以我有两种不同的布局用于WORecyclerListAdapter,ZWORecyclerListAdapter。如何创建一个适用于两个适配器的通用视图支架?您能帮我吗?@Naveen只需修改
WORecyclerListAdapter
中的
ViewHolder
,它同样适用于
ZWORecyclerListAdapter
,然后删除
ZWORecyclerListAdapter
中的
ViewHolder
声明,并将
WORecyclerListAdapter
ViewHolder导入到
ZWORecyclerListAdapter`是的,你说的是对的。但是我有不同的布局。WORecyclerListAdapter-workorder_list_content.xml,ZWORecyclerListAdapter-z_workorder_list_content.xml。对如何在WORecyclerListAdapter中为两者创建Viewholder感到困惑。