-3

I have been searching around google for two days but it is very hard found any luck with my problem. what I'm trying to achieve is I want to create an ExpandableListView in which every child has two value one to the right and another to the left, following question: How to achieve Expandablelistview child custom layout? was relevant but not fully as there are some elements which were missing

ExpandableListView View Design

This how I want to design my user interface, my array is something like this

[Parent 1 =[{Child 1, Child 1.1},{child 2,child 2.1},{child 3,child 3.1},{child 4, child 4.1},{child 5, child 5.1}],Parent 1=[{}]]

so on and so forth, now please help me out with the solution so that I can create a UI something like given

Younes
  • 462
  • 7
  • 15
Pratik Verma
  • 27
  • 1
  • 9
  • You can make custom class for your child. Try my sample to this question: https://stackoverflow.com/questions/50092400/values-of-counter-changes-after-scrolling-expendablelistview/50103780#50103780 Hope that helps! – i_A_mok Jun 08 '18 at 06:23
  • @I_A_Mok thank for help – Pratik Verma Jun 08 '18 at 09:14

1 Answers1

1

Use this CustomAdapter and use custom enter code herelayout as you want just create your layout.xml and use in this adapter

and try to Improve your R&d skills it is not a very big task , you spend two days to achieve it. any site does not provide code as you want thay only guide us, we need to improve that code as per our requirement

public class CustomAdapter extends BaseExpandableListAdapter {
    Context context;
    ArrayList<WeblListHeader> webHeader;

    public CustomAdapter(Context context, ArrayList<WeblListHeader> webHeader) {
        this.context = context;
        this.webHeader = webHeader;
    }

    @Override
    public int getGroupCount() {
        return webHeader.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return webHeader.get(i).getAl_state().size();
    }

    @Override
    public Object getGroup(int i) {
        return webHeader.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return webHeader.get(i).getAl_state().get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean isExpanded, View view, ViewGroup viewGroup) {
        if (view==null){

            LayoutInflater layoutInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutInflater.inflate(R.layout.your_expend_header_layout, null);
        }
        TextView tv_state = (TextView)view.findViewById(R.id.tv_name);

        ImageView iconExpend = (ImageView)view.findViewById(R.id.iconExpend);
        if (isExpanded) {
            iconExpend.setImageResource(R.drawable.arrow_up_selected);
            tv_state.setTextColor(context.getResources().getColor(R.color.selectedText));
        } else {
            iconExpend.setImageResource(R.drawable.arrow_down_unselect);
            tv_state.setTextColor(context.getResources().getColor(R.color.white));
        }

        tv_state.setText(webHeader.get(i).getStr_country());
        return view;
    }

    @Override
    public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {
        if (view==null){

            LayoutInflater layoutInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutInflater.inflate(R.layout.your_child_layout, null);
        }

        TextView tv_state = (TextView)view.findViewById(R.id.tv_name);

        tv_state.setText(webHeader.get(i).getAl_state().get(i1).getStr_name());
        tv_state.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }

let me know if it works for you and if any issue in this.

Sandeep Parish
  • 1,888
  • 2
  • 9
  • 20