3

In my expandablelistview some have children and some doesn't. GroupView's which have no children contain a Textview and a Button. On clicking the button, i need to pass the textview's data to next activity through intent. Now my problem is, i can't able to set the onclick event on groupview's button which has no child and i also need the groupPosition.

Here is my clickListener code in main java file:

expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            switch (groupPosition) {
                case 0:
                    Log.d(">>>", "" + groupPosition);
                    break;
                case 1:
                    Log.d(">>>", "" + groupPosition);
                    break;
                case 2:
                    Log.d(">>>", "" + groupPosition);
                    break;
                case 3:
                    Log.d(">>>", "" + groupPosition);
                    break;
            }
            return false;
        }
    });

Here is my adapter code:

public View getGroupView(int groupPosition, boolean isExpanded,
                         View convertView, ViewGroup parent) {
    groupIndex = groupPosition;
    QuotedListGroup group = (QuotedListGroup) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater inf = (LayoutInflater) context
                .getSystemService(context.LAYOUT_INFLATER_SERVICE);
        convertView = inf.inflate(R.layout.activity_expandable_listview, null);
    }

    if(groupPosition%2 == 0) {
        convertView.findViewById(R.id.part_1).setVisibility(View.VISIBLE);
        convertView.findViewById(R.id.part_2).setVisibility(View.GONE);
        //Other code..
    } else {
        convertView.findViewById(R.id.part_1).setVisibility(View.GONE);
        convertView.findViewById(R.id.part_2).setVisibility(View.VISIBLE);
        //Other code..
    }
    return convertView;
}

Actually, i need to show two different layouts for even numbered and odd numbered groups in the same expandablelistview.

Any help you can provide is greatly appreciated!

Mr.7
  • 2,292
  • 1
  • 20
  • 33
  • How you have added child in expandable list view – Pavya May 05 '16 at 13:20
  • 1
    add your adapter code also – Pavya May 05 '16 at 13:20
  • isn't that `getGroupView()` code enough? Other than that, i don't have my project specific code much in my adapter @Pravin – Mr.7 May 05 '16 at 13:30
  • I think this post is the same as to your other one that I answered. – AL. May 10 '16 at 03:33
  • Possible duplicate of [Multiple click events on expandablelistview's group element](http://stackoverflow.com/questions/37066670/multiple-click-events-on-expandablelistviews-group-element) – AL. May 10 '16 at 03:33

2 Answers2

2

like this

elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {

            Bundle bundle;
            switch (groupPosition) {
               case 0:
               //add your code here

            return false;
        }
    });
kirtan403
  • 7,293
  • 6
  • 54
  • 97
Manish
  • 353
  • 2
  • 18
  • I tried with `return false;` only. but i can't even enter into the above function. – Mr.7 May 05 '16 at 12:33
  • 1
    now i'm getting group position. but as soon as i click on groupView which has no child, my app is unfortunately closing. – Mr.7 May 05 '16 at 12:55
0

use ExpandableListView.OnGroupClickListener() it will also give you the group position.

Manish
  • 353
  • 2
  • 18
  • I already tried this. But it's not giving any groupPosition for groupview's which has no child – Mr.7 May 05 '16 at 12:29