Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.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_Boolean_Android Adapter - Fatal编程技术网

Java 布尔值不适用于RecyclerView中的按钮单击

Java 布尔值不适用于RecyclerView中的按钮单击,java,android,android-recyclerview,boolean,android-adapter,Java,Android,Android Recyclerview,Boolean,Android Adapter,我在适配器中为我的RecyclerView创建了2个Boolean。但是,由于某些原因,当单击相关按钮时,它们似乎不起作用,但是Toast却起作用。有人知道为什么布尔函数不能正常工作,以及如何解决这个问题吗 片段类 public class TabFragmentRV extends android.support.v4.app.Fragment { RecyclerView mRecyclerView; public TabFragmentRV() {} @Over

我在适配器中为我的
RecyclerView
创建了2个
Boolean
。但是,由于某些原因,当单击相关按钮时,它们似乎不起作用,但是
Toast
却起作用。有人知道为什么
布尔函数不能正常工作,以及如何解决这个问题吗

片段类

public class TabFragmentRV extends android.support.v4.app.Fragment {
    RecyclerView mRecyclerView;

    public TabFragmentRV() {}

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_rv, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        View v = getView();
        assert v != null;

        mRecyclerView = v.findViewById(R.id.my_recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));

        super.onActivityCreated(savedInstanceState);

        initRVAdapter();
    }

    private void initRVAdapter(){
        List<Object> itemsList = new ArrayList<>();

        // add items to the list
        itemsList.add(new MainHeader("Expand all", "Collapse all"));
        itemsList.add(new RVLineSeparator());
        itemsList.add(new SMSmessage("Item A","Item A description"));
        itemsList.add(new Phonecall("Item B","Item B description"));
        itemsList.add(new RVLineSeparator());
        itemsList.add(new RVSectionWith4CVs("Section W","W1","W1a","W2","W2a", "W3", "W3a", "W4", "W4a"));
        itemsList.add(new RVLineSeparator());
        itemsList.add(new RVTable("Item F1", "50ペンス", "50 펜스", "0,50 £", "50 пенсов"));
        itemsList.add(new RVLineSeparator());
        itemsList.add(new Phonecall("Item G1","Item G1 description"));

        RVItemsAapter itemsListAdapter = new RVItemsAapter(getContext());
        mRecyclerView.setAdapter(itemsListAdapter);

        itemsListAdapter.setCallSMSFeed(itemsList);
        itemsListAdapter.notifyDataSetChanged();
    }
}
public class RVItemsAapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private final static int TYPE_HEADER = 1, TYPE_EXPANDABLE = 2, TYPE_NONEXPANDABLE = 3, TYPE_SECTIONWITH4CARDS = 4, TYPE_TABLE = 5, TYPE_SEPARATOR = 6;
    private ArrayList myArrayList = new ArrayList();
    private boolean expandedAll;
    private boolean collapsedAll;

    private Context context;

//    private List items;

    public RVItemsAapter(Context context) { this.context = context}

    public void setCallSMSFeed(List<Object> myArrayList){
        this.myArrayList = (ArrayList) myArrayList;
    }

    @Override
    public int getItemViewType(int position) {
        if (myArrayList.get(position) instanceof MainHeader) {
            return TYPE_HEADER;
        } else if (myArrayList.get(position) instanceof Phonecall) {
            return TYPE_EXPANDABLE;
        } else if (myArrayList.get(position) instanceof SMSmessage) {
            return TYPE_NONEXPANDABLE;
        } else if (myArrayList.get(position) instanceof RVSectionWith4CVs) {
            return TYPE_SECTIONWITH4CARDS;
        } else if (myArrayList.get(position) instanceof RVTable) {
            return TYPE_TABLE;
        } else if (myArrayList.get(position) instanceof RVLineSeparator) {
            return TYPE_SEPARATOR;
        }
        throw new IllegalArgumentException("Item at position " + position + " is not an instance of either Phonecall or SMSmessage");
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        int viewType=holder.getItemViewType();
        switch (viewType){
            case TYPE_HEADER:
                MainHeader mainHeader = (MainHeader) myArrayList.get(position);
                ((MHeaderViewHolder)holder).showMHeaderDetails(mainHeader);
                break;
            case TYPE_EXPANDABLE:
                Phonecall call = (Phonecall) myArrayList.get(position);
                ((CallViewHolder)holder).showCallDetails(call);
                break;
            case TYPE_NONEXPANDABLE:
                SMSmessage sms = (SMSmessage) myArrayList.get(position);
                ((SMSViewHolder)holder).showSmsDetails(sms);
                break;
            case TYPE_SECTIONWITH4CARDS:
                RVSectionWith4CVs section4 = (RVSectionWith4CVs) myArrayList.get(position);
                ((Section4ViewHolder)holder).showSection4Details(section4);
                break;
            case TYPE_TABLE:
                RVTable mytbl = (RVTable) myArrayList.get(position);
                ((TblViewHolder)holder).showTblDetails(mytbl);
                break;
            case TYPE_SEPARATOR:
                ((SeparatorViewHolder)holder).showSeparatorDetails();
                break;
            default:
                throw new IllegalArgumentException("unexpected viewType: " + viewType);
        }
    }

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

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        int layout;
        RecyclerView.ViewHolder viewHolder;
        switch (viewType){
            case TYPE_HEADER:
                layout = R.layout.rv_header;
                View mainheaderView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new MHeaderViewHolder(mainheaderView);
                break;
            case TYPE_EXPANDABLE:
                layout = R.layout.cardview_dualline_withexpandability;
                View callsView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new CallViewHolder(callsView);
                break;
            case TYPE_NONEXPANDABLE:
                layout = R.layout.cardview_dualline_sansexpandability;
                View smsView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new SMSViewHolder(smsView);
                break;
            case TYPE_SECTIONWITH4CARDS:
                layout = R.layout.rv_item_sectionwith4cvs;
                View section4View = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new Section4ViewHolder(section4View);
                break;
            case TYPE_TABLE:
                layout = R.layout.cardview_tableview_withexpandability;
                View tblView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new TblViewHolder(tblView);
                break;
            case TYPE_SEPARATOR:
                layout = R.layout.lineseparatorforrecyclerview;
                View separatorView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new SeparatorViewHolder(separatorView);
                break;
            default:
                throw new IllegalArgumentException("unexpected viewType: " + viewType);
        }
        return viewHolder;
    }

    public class MHeaderViewHolder extends RecyclerView.ViewHolder {
        private Button btnExpandAll, btnCollapseAll;

        MHeaderViewHolder(View itemView) {
            super(itemView);
            btnExpandAll = itemView.findViewById(R.id.btn_expandall);
            btnCollapseAll = itemView.findViewById(R.id.btn_collapseall);

            btnExpandAll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    expandedAll = true;
                    collapsedAll = false;
                    notifyDataSetChanged();

                    Toast.makeText(context,"expand clicked",Toast.LENGTH_SHORT).show();
                }
            });

            btnCollapseAll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    expandedAll = false;
                    collapsedAll = true;
                    notifyDataSetChanged();

                    Toast.makeText(context,"collapse clicked",Toast.LENGTH_SHORT).show();
                }
            });
        }

        void showMHeaderDetails(MainHeader call){
            // code ommitted for easier reading
        }
    }

    public class CallViewHolder extends RecyclerView.ViewHolder {
        final Typeface iconFont = FontManager.getTypeface(context, FontManager.FONTAWESOME);

        private TextView arrowexpandcollapseTextView, callerNameTextView, callTimeTextView;
        private LinearLayout llFacilityInformation;

        CallViewHolder(View itemView) {
            super(itemView);
            arrowexpandcollapseTextView = itemView.findViewById(R.id.tv_cvwithexpandability_arrowexpandcollapse);
            callerNameTextView = itemView.findViewById(R.id.tv_cvwithexpandability_title);
            callTimeTextView = itemView.findViewById(R.id.tv_cvwithexpandability_subtitle);
            llFacilityInformation = itemView.findViewById(R.id.ll_cvwithexpandability_subtitle);

            arrowexpandcollapseTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llFacilityInformation.getVisibility() == View.GONE) {
                        expandLL(llFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            callerNameTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llFacilityInformation.getVisibility() == View.GONE) {
                        expandLL(llFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            llFacilityInformation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llFacilityInformation.getVisibility() == View.GONE) {
                        expandLL(llFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });


            // boolean decision making
            if (expandedAll) {
                expandLL(llFacilityInformation, arrowexpandcollapseTextView);
            } else if (collapsedAll) {
                collapseLL(llFacilityInformation, arrowexpandcollapseTextView);
            }
        }

        void showCallDetails(Phonecall call){
            arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_down);
            arrowexpandcollapseTextView.setTypeface(iconFont);
            llFacilityInformation.setVisibility(View.GONE);

            String callerName = call.getCallerName();
            String callTime = call.getCallTime();

            callerNameTextView.setText(callerName);
            callTimeTextView.setText(callTime);
        }
    }

    public class SMSViewHolder extends RecyclerView.ViewHolder {
        private TextView senderNameTextView, smsContentTextView;

        SMSViewHolder(View itemView) {
            super(itemView);
            senderNameTextView = itemView.findViewById(R.id.tv_cvsansexpandability_title);
            smsContentTextView = itemView.findViewById(R.id.tv_cvsansexpandability_subtitle);
        }

        void showSmsDetails(SMSmessage sms){
            // code ommitted for easier reading
        }
    }

    public class Section4ViewHolder extends RecyclerView.ViewHolder {
        final Typeface iconFont = FontManager.getTypeface(context, FontManager.FONTAWESOME);
        private LinearLayout llSectionInformation;
        private TextView arrowexpandcollapseTextView, sectionNameTextView, ticketofficetitleTextView, ticketofficedetailsTextView, ticketmachinestitleTextView, ticketmachinesdetailsTextView, gatestitleTextView, gatesdetailsTextView, atmspayphonestitleTextView, atmspayphonesdetailsTextView;

        Section4ViewHolder(View itemView) {
            super(itemView);
            // Initiate views
            arrowexpandcollapseTextView = itemView.findViewById(R.id.tv_section4headerforrv_expandcollapsearrow);
            sectionNameTextView = itemView.findViewById(R.id.tv_section4headerforrv_title);
            // ommitted code
            llSectionInformation = itemView.findViewById(R.id.ll_section4_cards);

            llSectionInformation.setVisibility(View.GONE);

            arrowexpandcollapseTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llSectionInformation.getVisibility() == View.GONE) {
                        expandLL(llSectionInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llSectionInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            sectionNameTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llSectionInformation.getVisibility() == View.GONE) {
                        expandLL(llSectionInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llSectionInformation, arrowexpandcollapseTextView);
                    }
                }
            });


            // boolean decision making
            if (expandedAll) {
                expandLL(llSectionInformation, arrowexpandcollapseTextView);
            } else if (collapsedAll) {
                collapseLL(llSectionInformation, arrowexpandcollapseTextView);
            }
        }

        void showSection4Details(RVSectionWith4CVs section){
            // code ommitted for easier reading
        }
    }

    public class TblViewHolder extends RecyclerView.ViewHolder {
        final Typeface iconFont = FontManager.getTypeface(context, FontManager.FONTAWESOME);

        private Button btnMale, btnFemale, btnWheelchairuser, btnBabychanging;
        private RelativeLayout rlFacilityInformation;
        private TextView arrowexpandcollapseTextView, sectionNameTextView;

        TblViewHolder(View itemView) {
            // code ommitted

            arrowexpandcollapseTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (rlFacilityInformation.getVisibility() == View.GONE) {
                        expandRL(rlFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseRL(rlFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            sectionNameTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (rlFacilityInformation.getVisibility() == View.GONE) {
                        expandRL(rlFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseRL(rlFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            // boolean decision making
            if (expandedAll) {
                expandRL(rlFacilityInformation, arrowexpandcollapseTextView);
            } else if (collapsedAll) {
                collapseRL(rlFacilityInformation, arrowexpandcollapseTextView);
            }
        }
    }

    public class SeparatorViewHolder extends RecyclerView.ViewHolder {
        private View lSeparator;

        SeparatorViewHolder(View itemView) {
            super(itemView);
            lSeparator = itemView.findViewById(R.id.rv_lineseparator);
        }

        void showSeparatorDetails(){
            TypedValue tValueD = new TypedValue();
            context.getTheme().resolveAttribute(R.attr.dividerColor, tValueD, true);

            lSeparator.setBackgroundResource(tValueD.resourceId);
        }
    }

    private void expandLL(final LinearLayout llFacilityInformation, final TextView arrowexpandcollapseTextView) {
        llFacilityInformation.setVisibility(View.VISIBLE);
        arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_up);
    }

    private void collapseLL(final LinearLayout llFacilityInformation, final TextView arrowexpandcollapseTextView) {
        llFacilityInformation.setVisibility(View.GONE);
        arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_down);
    }

    private void expandRL(final RelativeLayout rlFacilityInformation, final TextView arrowexpandcollapseTextView) {
        rlFacilityInformation.setVisibility(View.VISIBLE);
        arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_up);
    }

    private void collapseRL(final RelativeLayout rlFacilityInformation, final TextView arrowexpandcollapseTextView) {
        rlFacilityInformation.setVisibility(View.GONE);
        arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_down);
    }
}
公共类TabFragmentRV扩展了android.support.v4.app.Fragment{
回收视图mRecyclerView;
公共选项卡FragmentRV(){}
@凌驾
创建视图时的公共视图(@NonNull LayoutInflater inflater、@Nullable ViewGroup container、@Nullable Bundle savedInstanceState){
返回充气机。充气(右布局图。碎片_rv,容器,假);
}
@凌驾
ActivityCreated上的公共无效(@Nullable Bundle savedinStateCState){
视图v=getView();
断言v!=null;
mRecyclerView=v.findViewById(R.id.my\u recyclerview);
mRecyclerView.setLayoutManager(新的LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false));
super.onActivityCreated(savedInstanceState);
initRVAdapter();
}
私有void initRVAdapter(){
List itemsList=new ArrayList();
//将项目添加到列表中
添加(新的主标题(“全部展开”、“全部折叠”);
添加(新的RVLineSeparator());
项目列表添加(新SMS消息(“项目A”、“项目A说明”);
itemsList.add(新电话呼叫(“B项”、“B项说明”);
添加(新的RVLineSeparator());
添加项目列表(新RVSectionwith4CV(“SectionW”、“W1”、“W1a”、“W2”、“W2a”、“W3”、“W3a”、“W4”、“W4a”);
添加(新的RVLineSeparator());
项目列表添加(新RVTable(“项目F1”、“50ペンス", "50펜스", "0,50 £", "50 пенсов"));
添加(新的RVLineSeparator());
添加(新电话呼叫(“G1项”、“G1项说明”);
RVItemsAapter itemslistatadapter=新的RVItemsAapter(getContext());
mRecyclerView.setAdapter(itemsListAdapter);
itemsListAdapter.SetCallsMusFeed(itemsList);
itemsListAdapter.notifyDataSetChanged();
}
}
适配器类

public class TabFragmentRV extends android.support.v4.app.Fragment {
    RecyclerView mRecyclerView;

    public TabFragmentRV() {}

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_rv, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        View v = getView();
        assert v != null;

        mRecyclerView = v.findViewById(R.id.my_recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));

        super.onActivityCreated(savedInstanceState);

        initRVAdapter();
    }

    private void initRVAdapter(){
        List<Object> itemsList = new ArrayList<>();

        // add items to the list
        itemsList.add(new MainHeader("Expand all", "Collapse all"));
        itemsList.add(new RVLineSeparator());
        itemsList.add(new SMSmessage("Item A","Item A description"));
        itemsList.add(new Phonecall("Item B","Item B description"));
        itemsList.add(new RVLineSeparator());
        itemsList.add(new RVSectionWith4CVs("Section W","W1","W1a","W2","W2a", "W3", "W3a", "W4", "W4a"));
        itemsList.add(new RVLineSeparator());
        itemsList.add(new RVTable("Item F1", "50ペンス", "50 펜스", "0,50 £", "50 пенсов"));
        itemsList.add(new RVLineSeparator());
        itemsList.add(new Phonecall("Item G1","Item G1 description"));

        RVItemsAapter itemsListAdapter = new RVItemsAapter(getContext());
        mRecyclerView.setAdapter(itemsListAdapter);

        itemsListAdapter.setCallSMSFeed(itemsList);
        itemsListAdapter.notifyDataSetChanged();
    }
}
public class RVItemsAapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private final static int TYPE_HEADER = 1, TYPE_EXPANDABLE = 2, TYPE_NONEXPANDABLE = 3, TYPE_SECTIONWITH4CARDS = 4, TYPE_TABLE = 5, TYPE_SEPARATOR = 6;
    private ArrayList myArrayList = new ArrayList();
    private boolean expandedAll;
    private boolean collapsedAll;

    private Context context;

//    private List items;

    public RVItemsAapter(Context context) { this.context = context}

    public void setCallSMSFeed(List<Object> myArrayList){
        this.myArrayList = (ArrayList) myArrayList;
    }

    @Override
    public int getItemViewType(int position) {
        if (myArrayList.get(position) instanceof MainHeader) {
            return TYPE_HEADER;
        } else if (myArrayList.get(position) instanceof Phonecall) {
            return TYPE_EXPANDABLE;
        } else if (myArrayList.get(position) instanceof SMSmessage) {
            return TYPE_NONEXPANDABLE;
        } else if (myArrayList.get(position) instanceof RVSectionWith4CVs) {
            return TYPE_SECTIONWITH4CARDS;
        } else if (myArrayList.get(position) instanceof RVTable) {
            return TYPE_TABLE;
        } else if (myArrayList.get(position) instanceof RVLineSeparator) {
            return TYPE_SEPARATOR;
        }
        throw new IllegalArgumentException("Item at position " + position + " is not an instance of either Phonecall or SMSmessage");
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        int viewType=holder.getItemViewType();
        switch (viewType){
            case TYPE_HEADER:
                MainHeader mainHeader = (MainHeader) myArrayList.get(position);
                ((MHeaderViewHolder)holder).showMHeaderDetails(mainHeader);
                break;
            case TYPE_EXPANDABLE:
                Phonecall call = (Phonecall) myArrayList.get(position);
                ((CallViewHolder)holder).showCallDetails(call);
                break;
            case TYPE_NONEXPANDABLE:
                SMSmessage sms = (SMSmessage) myArrayList.get(position);
                ((SMSViewHolder)holder).showSmsDetails(sms);
                break;
            case TYPE_SECTIONWITH4CARDS:
                RVSectionWith4CVs section4 = (RVSectionWith4CVs) myArrayList.get(position);
                ((Section4ViewHolder)holder).showSection4Details(section4);
                break;
            case TYPE_TABLE:
                RVTable mytbl = (RVTable) myArrayList.get(position);
                ((TblViewHolder)holder).showTblDetails(mytbl);
                break;
            case TYPE_SEPARATOR:
                ((SeparatorViewHolder)holder).showSeparatorDetails();
                break;
            default:
                throw new IllegalArgumentException("unexpected viewType: " + viewType);
        }
    }

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

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        int layout;
        RecyclerView.ViewHolder viewHolder;
        switch (viewType){
            case TYPE_HEADER:
                layout = R.layout.rv_header;
                View mainheaderView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new MHeaderViewHolder(mainheaderView);
                break;
            case TYPE_EXPANDABLE:
                layout = R.layout.cardview_dualline_withexpandability;
                View callsView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new CallViewHolder(callsView);
                break;
            case TYPE_NONEXPANDABLE:
                layout = R.layout.cardview_dualline_sansexpandability;
                View smsView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new SMSViewHolder(smsView);
                break;
            case TYPE_SECTIONWITH4CARDS:
                layout = R.layout.rv_item_sectionwith4cvs;
                View section4View = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new Section4ViewHolder(section4View);
                break;
            case TYPE_TABLE:
                layout = R.layout.cardview_tableview_withexpandability;
                View tblView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new TblViewHolder(tblView);
                break;
            case TYPE_SEPARATOR:
                layout = R.layout.lineseparatorforrecyclerview;
                View separatorView = LayoutInflater
                        .from(parent.getContext())
                        .inflate(layout, parent, false);
                viewHolder = new SeparatorViewHolder(separatorView);
                break;
            default:
                throw new IllegalArgumentException("unexpected viewType: " + viewType);
        }
        return viewHolder;
    }

    public class MHeaderViewHolder extends RecyclerView.ViewHolder {
        private Button btnExpandAll, btnCollapseAll;

        MHeaderViewHolder(View itemView) {
            super(itemView);
            btnExpandAll = itemView.findViewById(R.id.btn_expandall);
            btnCollapseAll = itemView.findViewById(R.id.btn_collapseall);

            btnExpandAll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    expandedAll = true;
                    collapsedAll = false;
                    notifyDataSetChanged();

                    Toast.makeText(context,"expand clicked",Toast.LENGTH_SHORT).show();
                }
            });

            btnCollapseAll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    expandedAll = false;
                    collapsedAll = true;
                    notifyDataSetChanged();

                    Toast.makeText(context,"collapse clicked",Toast.LENGTH_SHORT).show();
                }
            });
        }

        void showMHeaderDetails(MainHeader call){
            // code ommitted for easier reading
        }
    }

    public class CallViewHolder extends RecyclerView.ViewHolder {
        final Typeface iconFont = FontManager.getTypeface(context, FontManager.FONTAWESOME);

        private TextView arrowexpandcollapseTextView, callerNameTextView, callTimeTextView;
        private LinearLayout llFacilityInformation;

        CallViewHolder(View itemView) {
            super(itemView);
            arrowexpandcollapseTextView = itemView.findViewById(R.id.tv_cvwithexpandability_arrowexpandcollapse);
            callerNameTextView = itemView.findViewById(R.id.tv_cvwithexpandability_title);
            callTimeTextView = itemView.findViewById(R.id.tv_cvwithexpandability_subtitle);
            llFacilityInformation = itemView.findViewById(R.id.ll_cvwithexpandability_subtitle);

            arrowexpandcollapseTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llFacilityInformation.getVisibility() == View.GONE) {
                        expandLL(llFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            callerNameTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llFacilityInformation.getVisibility() == View.GONE) {
                        expandLL(llFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            llFacilityInformation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llFacilityInformation.getVisibility() == View.GONE) {
                        expandLL(llFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });


            // boolean decision making
            if (expandedAll) {
                expandLL(llFacilityInformation, arrowexpandcollapseTextView);
            } else if (collapsedAll) {
                collapseLL(llFacilityInformation, arrowexpandcollapseTextView);
            }
        }

        void showCallDetails(Phonecall call){
            arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_down);
            arrowexpandcollapseTextView.setTypeface(iconFont);
            llFacilityInformation.setVisibility(View.GONE);

            String callerName = call.getCallerName();
            String callTime = call.getCallTime();

            callerNameTextView.setText(callerName);
            callTimeTextView.setText(callTime);
        }
    }

    public class SMSViewHolder extends RecyclerView.ViewHolder {
        private TextView senderNameTextView, smsContentTextView;

        SMSViewHolder(View itemView) {
            super(itemView);
            senderNameTextView = itemView.findViewById(R.id.tv_cvsansexpandability_title);
            smsContentTextView = itemView.findViewById(R.id.tv_cvsansexpandability_subtitle);
        }

        void showSmsDetails(SMSmessage sms){
            // code ommitted for easier reading
        }
    }

    public class Section4ViewHolder extends RecyclerView.ViewHolder {
        final Typeface iconFont = FontManager.getTypeface(context, FontManager.FONTAWESOME);
        private LinearLayout llSectionInformation;
        private TextView arrowexpandcollapseTextView, sectionNameTextView, ticketofficetitleTextView, ticketofficedetailsTextView, ticketmachinestitleTextView, ticketmachinesdetailsTextView, gatestitleTextView, gatesdetailsTextView, atmspayphonestitleTextView, atmspayphonesdetailsTextView;

        Section4ViewHolder(View itemView) {
            super(itemView);
            // Initiate views
            arrowexpandcollapseTextView = itemView.findViewById(R.id.tv_section4headerforrv_expandcollapsearrow);
            sectionNameTextView = itemView.findViewById(R.id.tv_section4headerforrv_title);
            // ommitted code
            llSectionInformation = itemView.findViewById(R.id.ll_section4_cards);

            llSectionInformation.setVisibility(View.GONE);

            arrowexpandcollapseTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llSectionInformation.getVisibility() == View.GONE) {
                        expandLL(llSectionInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llSectionInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            sectionNameTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llSectionInformation.getVisibility() == View.GONE) {
                        expandLL(llSectionInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseLL(llSectionInformation, arrowexpandcollapseTextView);
                    }
                }
            });


            // boolean decision making
            if (expandedAll) {
                expandLL(llSectionInformation, arrowexpandcollapseTextView);
            } else if (collapsedAll) {
                collapseLL(llSectionInformation, arrowexpandcollapseTextView);
            }
        }

        void showSection4Details(RVSectionWith4CVs section){
            // code ommitted for easier reading
        }
    }

    public class TblViewHolder extends RecyclerView.ViewHolder {
        final Typeface iconFont = FontManager.getTypeface(context, FontManager.FONTAWESOME);

        private Button btnMale, btnFemale, btnWheelchairuser, btnBabychanging;
        private RelativeLayout rlFacilityInformation;
        private TextView arrowexpandcollapseTextView, sectionNameTextView;

        TblViewHolder(View itemView) {
            // code ommitted

            arrowexpandcollapseTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (rlFacilityInformation.getVisibility() == View.GONE) {
                        expandRL(rlFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseRL(rlFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            sectionNameTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (rlFacilityInformation.getVisibility() == View.GONE) {
                        expandRL(rlFacilityInformation, arrowexpandcollapseTextView);
                    } else {
                        collapseRL(rlFacilityInformation, arrowexpandcollapseTextView);
                    }
                }
            });

            // boolean decision making
            if (expandedAll) {
                expandRL(rlFacilityInformation, arrowexpandcollapseTextView);
            } else if (collapsedAll) {
                collapseRL(rlFacilityInformation, arrowexpandcollapseTextView);
            }
        }
    }

    public class SeparatorViewHolder extends RecyclerView.ViewHolder {
        private View lSeparator;

        SeparatorViewHolder(View itemView) {
            super(itemView);
            lSeparator = itemView.findViewById(R.id.rv_lineseparator);
        }

        void showSeparatorDetails(){
            TypedValue tValueD = new TypedValue();
            context.getTheme().resolveAttribute(R.attr.dividerColor, tValueD, true);

            lSeparator.setBackgroundResource(tValueD.resourceId);
        }
    }

    private void expandLL(final LinearLayout llFacilityInformation, final TextView arrowexpandcollapseTextView) {
        llFacilityInformation.setVisibility(View.VISIBLE);
        arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_up);
    }

    private void collapseLL(final LinearLayout llFacilityInformation, final TextView arrowexpandcollapseTextView) {
        llFacilityInformation.setVisibility(View.GONE);
        arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_down);
    }

    private void expandRL(final RelativeLayout rlFacilityInformation, final TextView arrowexpandcollapseTextView) {
        rlFacilityInformation.setVisibility(View.VISIBLE);
        arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_up);
    }

    private void collapseRL(final RelativeLayout rlFacilityInformation, final TextView arrowexpandcollapseTextView) {
        rlFacilityInformation.setVisibility(View.GONE);
        arrowexpandcollapseTextView.setText(R.string.fa_icon_chevron_down);
    }
}
public类RVItemsAapter扩展了RecyclerView.Adapter{
专用最终静态整型整型头=1,整型可扩展=2,整型不可扩展=3,整型节带4个卡片=4,整型表=5,整型分隔符=6;
private ArrayList myArrayList=new ArrayList();
私有布尔扩展all;
私有布尔collapsedAll;
私人语境;
//私人清单项目;
public RVItemsAapter(上下文){this.Context=Context}
公共void setCallsFeed(列表myArrayList){
this.myArrayList=(ArrayList)myArrayList;
}
@凌驾
public int getItemViewType(int位置){
if(myArrayList.get(position)instanceof MainHeader){
返回类型_头;
}else if(myArrayList.get(position)instanceof Phonecall){
返回式可扩展;
}else if(myArrayList.get(position)实例SMSmessage){
返回类型_不可扩展;
}else if(myArrayList.get(position)instanceof rvsection with 4cvs){
带4个卡的返回式_段;
}else if(myArrayList.get(position)instanceof RVTable){
返回类型_表;
}else if(myArrayList.get(position)instanceof RVLineSeparator){
返回式分离器;
}
抛出新的IllegalArgumentException(“位置“+position+”处的项不是Phonecall或SMSmessage的实例”);
}
@凌驾
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder,int位置){
int viewType=holder.getItemViewType();
开关(视图类型){
案例类型_标题:
MainHeader MainHeader=(MainHeader)myArrayList.get(position);
((mheaderwilder)支架)。显示mheaderDetails(主标题);
打破
案例类型\u可扩展:
Phonecall call=(Phonecall)myArrayList.get(位置);
((CallViewHolder)holder)。showCallDetails(通话);
打破
案例类型_不可扩展:
SMSmessage sms=(SMSmessage)myArrayList.get(位置);
((SMSViewHolder)支架)。显示详细信息(sms);
打破
带4个卡的箱型_部分:
RVSectionWith4CVs section4=(RVSectionWith4CVs)myArrayList.get(位置);
((Section4ViewHolder)holder)。显示Section4Details(section4);
打破
案例类型表:
RVTable mytbl=(RVTable)myArrayList.get(position);
((TblViewHolder)支架)。显示详细信息(mytbl);
打破
箱型分离器:
((分离器视图支架)支架)。显示分离器详细信息();
打破
违约:
抛出新的IllegalArgumentException(“意外视图类型:+viewType”);
}
}
@凌驾
public int getItemCount(){return myArrayList.size();}
@非空
@凌驾
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup父级,int-viewType){
int布局;
RecyclerView.ViewHolder-ViewHolder;
开关(视图类型){
案例类型_标题:
布局=R.layout.rv_集管;
视图mainheaderView=布局平坦器
.from(parent.getContext())
.充气(布局、父级、假);
viewHolder=新的mHeaderViewWholder(mainheaderView);
打破
案例类型\u可扩展:
layout=R.layout.cardview_双线_,具有可扩展性;
视图调用视图=布局展开器
.from(parent.getContext())
.充气(布局、父级、假);
观众=