androidandroid-recyclerviewexpandablerecyclerview

What is this recycler view or listview it contains four buttons?


I want to create a expandable list with four child buttons in a row. And also click working on that buttons. what can i use in android studio. i have checked so many even tried expandable ListView that is generating child in the vertical manner.

enter image description here


Solution

  • Solution 1: Use ExpandableListView and in the group_child_layout take four ImageView(Whatever Buttons).

    Assign respective data(e.g assign a phone number value to call_icon). Example below:

     @Override
     public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    
        ChildHolder childHolder = null;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.item_group_child, parent, false);
            childHolder = new ChildHolder();
            convertView.setTag(childHolder);
        }
        else {
            childHolder = (ChildHolder) convertView.getTag();
        }
    
        /* Assign all the buttons their respective data from ContactData object*/
    
        return convertView;
    }
    

    Solution 2: Use ExpandableListView and in the group_child_layout take a RecyclerView(for horizontal buttons list) in it. Example below:

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    
        ChildHolder childHolder = null;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.item_group_child, parent, false);
            childHolder = new ChildHolder();
            convertView.setTag(childHolder);
        }
        else {
            childHolder = (ChildHolder) convertView.getTag();
        }
    
        childHolder.horizontalListView = (RecyclerView) convertView.findViewById(R.id.buttons);
        LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
        childHolder.horizontalListView.setLayoutManager(layoutManager);
    
        ButtonsAdapter horizontalListAdapter = new ButtonsAdapter(context, brands.get(groupPosition).buttons);
        childHolder.horizontalListView.setAdapter(horizontalListAdapter);
    
        return convertView;
    }