如何在单个回收站视图中设置两个不同的Type数组数据

时间:2018-09-05 05:24:57

标签: android

我有两种类型的数组,其中数组A具有文件夹名称,数组B具有文档列表。我想在单个回收站视图中显示两个阵列。问题是当我在Adapter类内运行for循环时,仅反映了最后一个元素名称。

public class PersonalDocumentsAdapter extends RecyclerView.Adapter<PersonalDocumentsAdapter.MyViewHolder> {

    ArrayList<PersonalDoucmentsModel> arrayList;
    IdownloadClick idownloadClick;
    int count;
    private Context mContext;
    private Activity mActiity;


    public PersonalDocumentsAdapter(Context mContext, ArrayList<PersonalDoucmentsModel> arrayList, IdownloadClick idownloadClick, int count) {
        this.mContext = mContext;
        this.arrayList = arrayList;
        this.idownloadClick = idownloadClick;
        this.count = count;

    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {


        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.cell_personal_documents, parent, false);

        return new MyViewHolder(itemView);

    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, int position) {

        if (arrayList.get(0).getWrapperListArrayList() != null) {

            holder.mBinding.fileName.setText(arrayList.get(0).getWrapperListArrayList().get(position).getFolderName());
        }

        if (arrayList.get(0).getAttachmentWrapperLists() != null) {
            holder.mBinding.fileName.setText(arrayList.get(0).getAttachmentWrapperLists().get(position).getDocumentName());

        }
    }

    @Override
    public int getItemCount() {
        return count;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }


    public class MyViewHolder extends RecyclerView.ViewHolder {
        CellPersonalDocumentsBinding mBinding;

        MyViewHolder(View itemView) {
            super(itemView);
            mBinding = DataBindingUtil.bind(itemView);
        }

        public CellPersonalDocumentsBinding getmBinding() {
            return mBinding;
        }
    }
}

0 个答案:

没有答案