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感到困惑。