Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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
Android 标题显示数据但减去1的Recylerview_Android - Fatal编程技术网

Android 标题显示数据但减去1的Recylerview

Android 标题显示数据但减去1的Recylerview,android,Android,所以我有三条记录,但当我试图通过我的android应用程序显示它时,它只显示了两条 这是我的recylerview适配器 public class Sales_header_adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1;

所以我有三条记录,但当我试图通过我的android应用程序显示它时,它只显示了两条

这是我的recylerview适配器

   public class Sales_header_adapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static final int TYPE_HEADER = 0;
    private static final int TYPE_ITEM = 1;
    private List<Sales_header_model> salesheaderlist;

    public Sales_header_adapter(List<Sales_header_model> salesheaderlist) {
        this.salesheaderlist = salesheaderlist;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_ITEM) {
            View VHItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.sales_header_rec, parent, false);
            return new VHItem(VHItem);
        } else if (viewType == TYPE_HEADER) {
            View VHHeader = LayoutInflater.from(parent.getContext()).inflate(R.layout.sales_header_rec_header, parent, false);
            return new VHHeader(VHHeader);
        }
        throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof VHItem) {
            Sales_header_model as =  salesheaderlist.get(position);
            VHItem VHitem = (VHItem)holder;
            VHitem.nonota.setText(as.getNoNota());
            VHitem.tanggal.setText(as.getTanggalTransaksi());
            VHitem.total.setText("Rp. 1.000.000");

        } else if (holder instanceof VHHeader) {
            Sales_header_model dataItem = getItem(position);
            VHHeader VHheader = (VHHeader)holder;
            VHheader.nonota_h.setText("No Nota");
            VHheader.tanggal_h.setText("Tanggal");
            VHheader.total_h.setText("Total");
        }
    }

    @Override
    public int getItemCount() {
        return salesheaderlist.size();
    }

    @Override
    public int getItemViewType(int position) {
        if (isPositionHeader(position))
            return TYPE_HEADER;
        return TYPE_ITEM;
    }

    private boolean isPositionHeader(int position) {
        return position  == -1;
    }

    private Sales_header_model getItem(int position) {
        return salesheaderlist.get(position);
    }

    class VHItem extends RecyclerView.ViewHolder {
        public TextView  tanggal, total,nonota;
        public VHItem(View itemView) {
            super(itemView);
            tanggal         =  itemView.findViewById(R.id.tanggalnota);
            total           =  itemView.findViewById(R.id.total);
            nonota          =  itemView.findViewById(R.id.nonota);
        }
    }

    class VHHeader extends RecyclerView.ViewHolder {
        public TextView  tanggal_h, total_h,nonota_h;
        public VHHeader(View itemView) {
            super(itemView);
            tanggal_h               = itemView.findViewById(R.id.tanggalnota_h);
            total_h                 = itemView.findViewById(R.id.total_h);
            nonota_h                = itemView.findViewById(R.id.nonota_h);
        }
    }
}
public class Sales\u header\u适配器扩展了RecyclerView.adapter{
私有静态最终int TYPE_头=0;
私有静态最终整数类型\ u项=1;
私人名单推销员;
公共销售\标题\适配器(列表salesheaderlist){
this.salesheaderlist=salesheaderlist;
}
@凌驾
public RecyclerView.ViewHolder onCreateViewHolder(视图组父级,int-viewType){
if(viewType==类型\项){
查看VHItem=LayoutInflater.from(parent.getContext())。充气(R.layout.sales\u header\u rec,parent,false);
返回新的VHItem(VHItem);
}else if(viewType==类型\标题){
查看VHHeader=LayoutFlater.from(parent.getContext())。充气(R.layout.sales\u header\u rec\u header,parent,false);
返回新的VHHeader(VHHeader);
}
抛出新的RuntimeException(“没有与类型“+viewType+”+匹配的类型,请确保正确使用类型”);
}
@凌驾
BindViewHolder上的公共无效(RecyclerView.ViewHolder,int位置){
if(VHF项目的持有人实例){
Sales\u header\u model as=salesheaderlist.get(位置);
VHItem VHItem=(VHItem)持有人;
VHitem.nonota.setText(as.getNoNota());
VHitem.tanggal.setText(as.getTanggalTransaksi());
VHitem.total.SETEXT(“1.000.000卢比”);
}else if(VHHeader的保持架实例){
销售\表头\型号dataItem=getItem(位置);
VHHeader VHHeader=(VHHeader)支架;
VHheader.nonota_h.SETEXT(“无Nota”);
VHheader.tanggal_h.SETEXT(“tanggal”);
VHheader.total_h.setText(“总计”);
}
}
@凌驾
public int getItemCount(){
return salesheaderlist.size();
}
@凌驾
public int getItemViewType(int位置){
if(isPositionHeader(位置))
返回类型_头;
返回类型\ U项目;
}
专用布尔值isPositionHeader(int位置){
返回位置==-1;
}
私人销售\表头\型号getItem(内部位置){
返回salesheaderlist.get(位置);
}
VHItem类扩展了RecyclerView.ViewHolder{
公共文本视图tanggal,总计,非OTA;
公共项目(查看项目视图){
超级(项目视图);
tanggal=itemView.findViewById(R.id.tanggalnota);
总计=itemView.findViewById(R.id.total);
nonota=itemView.findviewbyd(R.id.nonota);
}
}
类别VHHeader扩展了RecyclerView.ViewHolder{
公共文本视图tanggal_h、total_h、nonota_h;
公共标题(查看项目视图){
超级(项目视图);
tanggal_h=itemView.findViewById(R.id.tanggalnota_h);
total_h=itemView.findviewbyd(R.id.total_h);
nonota_h=itemView.findViewById(R.id.nonota_h);
}
}
}
从我的
getItemCount
中,我得到
3
。我怎样才能修好它,提前谢谢。参考

执行以下操作:

private boolean isPositionHeader(int position) {
        return position == 0;
    }

private Sales_header_model getItem(int position) {
    return salesheaderlist.get(position - 1);
}
而不是:

private boolean isPositionHeader(int position) {
        return position  == -1;
    }
private Sales_header_model getItem(int position) {
    return salesheaderlist.get(position);
}

它从我的
RecyclerView.ViewHolder中抛出了一个错误。你能提到完整的适配器类吗?我仍然得到一个错误。以下是错误`java.lang.ArrayIndexOutOfBoundsException:length=10;索引=-1`